我有一个强类型的 View 。这个强类型有一个由byte[]组成的字段,这个数组包含一张图片。
是否可以用@Html.Image(Model.myImage) 之类的东西来显示这张图片?
非常感谢
最佳答案
您可以创建一个 Controller 操作方法,将图像作为 FileContentResult 返回:
public FileContentResult Display(string id) {
byte[] byteArray = GetImageFromDB(id);
return new FileContentResult(byteArray, "image/jpeg");
}
然后您可以使用模型中的图像 ID 创建指向 View 中操作方法的 ActionLink。
关于c# - 使用 ASP.Net MVC3 显示 byte[] 中包含的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6040920/