显示包含在与ASP.Net MVC3一个字节[]的图像 [英] Display an image contained in a byte[] with ASP.Net MVC3

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

问题描述

我有一个强类型的视图。这种强烈的类型有由字节[]的领域,这个数组包含了图片。

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一个字节[]的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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