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

查看:78
本文介绍了ASP.Net 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.

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

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