How can I load URL path from database from to view with foreign key "BAZ_ID"?
IMAGE_URL:
~/UploadImg/Untitled.png
Controller:
public ActionResult Bazar()
{
WebEntities db = new WebEntities();
var data = db.bazar.Include(c => c.images);
return View(data.ToList());
}
And view:
<div class="col-sm-2">
<img src= "@Url.Content(modelItem => item.images.Where(a => a.BAZ_ID == item.ID).Select(b => b.IMAGE_URL).FirstOrDefault())" width="150" height="150" />
</div>
In view I get error:
Cannot convert lambda expression to type 'string' because it is not a delegate type
modelItem =>. But your queries belong in the controller, not the view and you should be passing a view model that contains a property for the image url. - user3559349FirstOrDefault()is not guaranteed to return an object that is notnull. - Timothy Groote