显示数据库中的图像

时间:2011-10-21 07:15:39

标签: c# asp.net-mvc razor

我需要显示数据库中的图像。 在控制器中:

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="" />
}

无效

1 个答案:

答案 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");
}