У меня возник вопрос о показе изображений, загруженных из базы данных mysql в виде индекса.Ошибка при загрузке изображений из базы данных
В моей таблице базы данных «Конечные результаты» у меня есть «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 id)
{
IQueryable<byte[]> data = repository.GetImages(id);
byte[] firstimage = data.First();
return File(firstimage, "image/png");
}
Repository:
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 itemID)
{
return from deliverable in entities.deliverables
where deliverable.item_id.Equals(itemID)
select deliverable.deliverable_image;
}
Вид:
@foreach(var imgID in Model.DeliverablesIDsList)
{
<img src="@Url.Action("ShowImage", "Deliverable", new { DeliverableID = imgID })" />
}
В моей ViewModel у меня есть:
public List<long> DeliverablesIDsList { get; set; }
public int DeliverableID { get; set; }
Но теперь я всегда получаю эту ошибку:
he model item passed into the dictionary is of type 'System.Collections.Generic.List`1[System.Int64]', but this dictionary requires a model item of type 'GDMfrontEnd.Models.DeliverableViewModel'.
ли кто-то знает, что я делаю неправильно?
Спасибо! Проблема теперь в действии showImage:/Он не показывает изображения :(Возможно, вы знаете, в чем проблема? Похоже, что он не пришел в действие ... – nielsv
проверить сейчас .. –
Спасибо , ты лучший! – nielsv