Asp.net mvc 4 如何使用mvc在路径存储在db中的图像控件中显示图像
如何在图像控件中显示其路径存储在数据库中的图像。 请提供我的样本代码,我已经从数据库中获得的路径,但我如何才能显示在图像控制。 这是我的密码Asp.net mvc 4 如何使用mvc在路径存储在db中的图像控件中显示图像,asp.net-mvc-4,Asp.net Mvc 4,如何在图像控件中显示其路径存储在数据库中的图像。 请提供我的样本代码,我已经从数据库中获得的路径,但我如何才能显示在图像控制。 这是我的密码 [HttpPost] public ActionResult DisplayPic() { string UserName=User.Identity.Name; var getPath = from p in Session.Query<Registration>()
[HttpPost]
public ActionResult DisplayPic()
{
string UserName=User.Identity.Name;
var getPath = from p in Session.Query<Registration>()
where p.Email == UserName
select p.Path;
if (getPath.Count() > 0)
{
//display pic???
}
return View();
}
[HttpPost]
公共行动结果显示PIC()
{
字符串UserName=User.Identity.Name;
var getPath=来自会话中的p.Query()
其中p.Email==用户名
选择p.路径;
if(getPath.Count()>0)
{
//显示图片???
}
返回视图();
}
视图:
@{
ViewBag.Title=“DisplayPic”;
}
显示图片
@使用(Html.BeginForm())
{
}
在模型属性中存储图像路径并使用
<img src="@Url.Content(Model.ImagePath)" alt = "Image" />
向模型中添加字符串变量(例如“ImageUrl”)这给了我一个错误,无法对空引用执行运行时绑定。我如何传递img src中的ImageUrl值,该值是我在DisplayPic方法中从db获得的。我不知道它将如何显示特定用户的配置文件映像。我已经获得了要显示的映像的路径,但我如何才能将该路径提供给映像在模型类中为imagepath提供一个附加属性
<img src="@Url.Content(Model.ImagePath)" alt = "Image" />