dan henderson
asked on
how to pass image source from model property.
I have a razor view index that gets @model IEnumerable<Test.Models.Pe t> collection from the controller. The model has 2 properties, ImageUrl and Name.
I build the view this way:
@for (int cnt=0;cnt<Model.Count();cn t++)
{
//string imageUrl = @Model.ElementAt(cnt).Imag eUrl;
if (cnt == 0)
{
<div class="col span-1-of-4 box">
<h4>@Html.DisplayFor(model => model.ElementAt(cnt).Name) </h4>
<img src="WHAT GOES HERE" alt="@Html.DisplayFor(mode l => model.ElementAt(cnt).Image Url)" width="100" height="100" />
</div>
}
}
I can get the imageurl value in the alt attribute(just to see what I've returned), but can't figure out what to put in the src="" attribute. Please help.
I build the view this way:
@for (int cnt=0;cnt<Model.Count();cn
{
//string imageUrl = @Model.ElementAt(cnt).Imag
if (cnt == 0)
{
<div class="col span-1-of-4 box">
<h4>@Html.DisplayFor(model
<img src="WHAT GOES HERE" alt="@Html.DisplayFor(mode
</div>
}
}
I can get the imageurl value in the alt attribute(just to see what I've returned), but can't figure out what to put in the src="" attribute. Please help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to help you!
ASKER