我需要显示数据库中的图像。 在控制器中:
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="" />
}
无效
答案 0 :(得分:0)
您的控制器方法需要Document doc
,但您的网址只定义了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");
}