0
我是最后一年的学生,从事五年规划,我有一个关于在二进制数据中存储图像的问题。我尝试了很多解决方案,我在Google上搜索过,但没有解决任何问题。如何在MVC列表中显示图像?
查看
@model IEnumerable<PictureServices.Picture>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
<tr>
@foreach (var item in Model)
{
<td>
@{
var base64 = Convert.ToBase64String(item.image);
var imgsrc = string.Format("data:image/jpg;base64,{0}", base64);
}
<img src='@imgsrc' style="max-width:100px; max-height:100px;">
</td>
模型
public class Picture
{
public int id { get; set; }
public byte[] image { get; set; }
public string name { get; set; }
}
控制器
public class CarServicesController : Controller
{
TestingEntities db = new TestingEntities();
public ActionResult Index()
{
Picture ds = new Picture();
var item = (from d in db.Pictures
select d).ToList();
return View(item);
}
我按照您的指示尝试了这一个,但它没有起作用,调试在断点处停止。 –
你有没有例外? – Shyju
显示没有任何错误,浏览器稍后搜索后重定向回Controller文件。 VS中没有显示任何错误。 –