使用 ASP.Net MVC3 显示包含在 byte[] 中的图像 [英] Display an image contained in a byte[] with ASP.Net MVC3

查看:20
本文介绍了使用 ASP.Net MVC3 显示包含在 byte[] 中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个强类型的视图.这个强类型有一个由byte[]组成的字段,这个数组包含一张图片.

I've a view with a strong type. This strong type has a field consisting of a byte[], this array contains a picture.

是否可以使用@Html.Image(Model.myImage) 之类的内容显示此图像?

Is it possible to display this image with something like @Html.Image(Model.myImage) ?

非常感谢

推荐答案

您可以创建一个控制器操作方法,将图像作为 FileContentResult 返回:

You can create a controller action method that returns an image as a FileContentResult:

public FileContentResult Display(string id) {
   byte[] byteArray = GetImageFromDB(id);
   return new FileContentResult(byteArray, "image/jpeg");
}

然后,您可以使用模型中的图像 ID 在视图中创建指向操作方法的 ActionLink.

Then you can create an ActionLink to the action method in the view using the image id from the model.

这篇关于使用 ASP.Net MVC3 显示包含在 byte[] 中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆