MVC如何显示从模型中的字节数组图像 [英] MVC How to display a byte array image from model

查看:91
本文介绍了MVC如何显示从模型中的字节数组图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾与一个字节数组图像文件的模式,我想显示在页面上。

I've a model with a byte array image file that I want to show on the page.

我怎么能做到这一点,而不必返回到数据库?

How can I do that without going back to the Database?

所有我看到用一个ActionResult回到数据库检索图像的解决方案,但我已经有模型上的图像...

All the solutions that I see use an ActionResult to go back to the database to retrieve the image, but I already have the image on the model...

推荐答案

这样的事情可能工作...

Something like this may work...

@{
    var base64 = Convert.ToBase64String(Model.ByteArray);
    var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
}

<img src="@imgSrc" />

由于在下面的评论中提到,请使用上面与的知识武装虽然这可能会回答你的问题可能无法解决您的问题的。根据您的问题,这可能是解决方案,但我不会完全排除访问数据库的两倍。

As mentioned in the comments below, please use the above armed with the knowledge that although this may answer your question it may not solve your problem. Depending on your problem this may be the solution but I wouldn't completely rule out accessing the database twice.

这篇关于MVC如何显示从模型中的字节数组图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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