我是 MVC 2 的新手,非常感谢任何帮助。
在我的数据库中,我有一个存储为 System.Drawing.BitMap 的缩略图字段。
我有一个局部 View 需要在 html 中生成图像。
我看到了指向 FileResult 的链接,但这是 Controller 。通过模型绑定(bind),我如何从局部 View 将图像嵌入到生成的 html 页面中?
不确定我的 html 中是否需要一些“图像”标签,或者部分 View 中的数据必须采用什么格式才能显示缩略图?
京东
最佳答案
您需要有一个返回 FileStreamResult 的 Controller 操作,然后使用 <img>
指向此 Controller 操作的标记。
public ActionResult Image(int id)
{
byte[] imageData = GetImageFromDb(id);
return File(imageData, "image/jpeg");
}
然后在您的 View 中:
<img src="<%: Url.Action("image", new { id = Model.ImageId }) %>" alt="some image" />
关于c# - 如何获取要在 MVC 2 中显示的位图图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4520859/