【发布时间】:2011-11-25 12:37:21
【问题描述】:
我使用 EF 4.1 Code First,为了简单起见,假设我有以下实体类:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Byte[] Image { get; set; }
}
我已经设法创建了一个允许将 Person 对象添加到数据库中的有效创建视图。
但是当我要显示一个人的详细信息时,我会卡在显示图像上。经过一番研究,我有以下几点:
// To convert the Byte Array to the author Image
public FileContentResult getImg(int id)
{
byte[] byteArray = DbContext.Persons.Find(id).Image;
return byteArray != null
? new FileContentResult(byteArray, "image/jpeg")
: null;
}
在我试图列出人员详细信息的视图中,我有以下内容来显示要显示的图像:
<img src="@Html.Action("getImg", "Person", new { id = item.Id })" alt="Person Image" />
但是以上方法不起作用,我的图像源 [src] 属性返回空。
【问题讨论】:
标签: arrays asp.net-mvc image asp.net-mvc-3 razor