Image 在MVC4视图中显示字节数组图像
我正在尝试在视图中显示图像 我已经编写了一个图像助手:Image 在MVC4视图中显示字节数组图像,image,asp.net-mvc-4,html-helper,Image,Asp.net Mvc 4,Html Helper,我正在尝试在视图中显示图像 我已经编写了一个图像助手: public static class Helpers { public static FileContentResult Image(this HtmlHelper htmlHelper, byte[] imageData, string mimeType) { return new FileContentResult(imageData, mime
public static class Helpers
{
public static FileContentResult Image(this HtmlHelper htmlHelper,
byte[] imageData, string mimeType)
{
return new FileContentResult(imageData, mimeType);
}
}
myImage-是一个字节数组
<img src="@Html.Image(myImage, "image/jpeg")" />
但是我的图像没有显示
当我看源代码时,我看到的是:
<img src="System.Web.Mvc.FileContentResult">
有人吗?:) 您这样做是在
src=”“
的引号之间返回FileContentResult
我知道你想做什么,但是为了让它工作,
需要请求图像的URL,而不是简单地将字节[]
放在src中。因此,您需要设置一个操作方法,该方法接受一些参数并返回FileContentResult
请查看此问题的答案