显示数据库中的图像
本文关键字:图像 数据库 显示 | 更新日期: 2023-09-27 18:11:48
我需要显示来自数据库的图像。在控制器:
public ActionResult Display(int id, Document doc)
{
byte[] byteArray = doc.Content;//its has the image in bytes
return new FileStreamResult(new System.IO.MemoryStream(byteArray), "image/jpeg");
}
在视图:@foreach (var imgsrc in Model.ImagesSrc)
{
<img src="@Url.Action( "Display", "image", new { id = @imgsrc.Id } )" alt="" />
}
不工作
您的控制器方法期望Document doc
,但您的url仅定义id。您应该在下载方法中以id
public ActionResult Display(int id)
{
Document doc = GetDocById(id);
byte[] byteArray = doc.Content;//its has the image in bytes
return new FileStreamResult(new System.IO.MemoryStream(byteArray), "image/jpeg");
}