【发布时间】:2013-06-01 15:12:45
【问题描述】:
我有一个关于在视图中显示从 mysql 数据库加载的图像的问题。
在我的数据库表“deliverables”中,我有“item_id”、“deliverable_image”和“afstudeerrichting_id”。 "item_id" 和 "afstudeerrichting_id" 是来自其他表的 FK。
我想在 afstudeerrichting_id = ..时显示图像
控制器:
public ActionResult Index()
{
var model = repository.GetIdsOfImages(1);
return View(model.ToList());
}
public ActionResult ShowImage(int afstudeerrichtingid)
{
IQueryable<byte[]> data = repository.GetImages(afstudeerrichtingid);
var thedata = data.First();
return File(thedata, "image/png");
}
存储库(我在其中获取图像):
public IQueryable<long> GetIdsOfImages(int afstudeerrichtingid)
{
return from deliverable in entities.deliverables
where deliverable.afstudeerichting_id.Equals(afstudeerrichtingid)
select deliverable.item_id;
}
public IQueryable<byte[]> GetImages(int afstudeerrichtingid)
{
return from deliverable in entities.deliverables
where deliverable.afstudeerichting_id.Equals(afstudeerrichtingid)
select deliverable.deliverable_image;
}
查看:
@foreach(var imgID in Model.DeliverablesIDsList)
{
<img src="@Url.Action("ShowImage", "Deliverable", new { DeliverableID = imgID })" />
}
在我的视图模型中:
public List<long> DeliverablesIDsList { get; set; }
public int DeliverableID { get; set; }
现在我得到错误:
传入字典的模型项的类型为“System.Collections.Generic.List`1[System.Int64]”,但此字典需要“GDMfrontEnd.Models.DeliverableViewModel”类型的模型项。
我应该在我的 ViewModel 中进行哪些更改?还是我做错了什么?
【问题讨论】:
-
标题不需要加标签,标签就是这么用的!请阅读meta.stackexchange.com/q/19190/147072了解更多信息
标签: asp.net asp.net-mvc image view iqueryable