Asp.net mvc 2 如何在asp.net MVC 2中填充映像

Asp.net mvc 2 如何在asp.net MVC 2中填充映像,asp.net-mvc-2,Asp.net Mvc 2,我正在应用程序域文件系统中保存用户映像。以及数据库中的存储路径。我正在我的User.PhotoPath属性中获取路径。我想在这个光路的页面上显示图像。我怎么展示它 我使用的是Asp.net MVC 2+C#。将光路作为viewmodel上的属性提供: public class UserViewModel { //... public string PhotoPath { get; set; } } 控制器: public ActionResult Show(int id) {

我正在应用程序域文件系统中保存用户映像。以及数据库中的存储路径。我正在我的
User.PhotoPath属性中获取路径。我想在这个
光路的页面上显示图像。我怎么展示它


我使用的是Asp.net MVC 2+C#。

将光路作为viewmodel上的属性提供:

public class UserViewModel
{
    //...
    public string PhotoPath { get; set; }
}
控制器:

public ActionResult Show(int id) 
{
    // load User entity from repository
    var viewModel = new UserViewModel();
    // populate viewModel from User entity
    return View(viewModel);
}
ViewData["PhotoPath"] = yourUser.Photopath;
视图:


在viewmodel上提供光路作为属性:

public class UserViewModel
{
    //...
    public string PhotoPath { get; set; }
}
控制器:

public ActionResult Show(int id) 
{
    // load User entity from repository
    var viewModel = new UserViewModel();
    // populate viewModel from User entity
    return View(viewModel);
}
ViewData["PhotoPath"] = yourUser.Photopath;
视图:


将用户设置为视图的模型,并使用PhotopPath作为图像元素的源

<img src="<%= model.PhotoPath %>" alt="whatever you want" />
<img src="<%= ViewData["PhotoPath"].ToString() %>" alt="whatever you want" />
视图:

“alt=”你想要什么“/>

将用户设置为视图的模型,并使用PhotopPath作为图像元素的源

<img src="<%= model.PhotoPath %>" alt="whatever you want" />
<img src="<%= ViewData["PhotoPath"].ToString() %>" alt="whatever you want" />
视图:

“alt=”你想要什么“/>