codeme codeme - 21 days ago 6
ASP.NET (C#) Question

How to show images in a gridview after iterating over a list of Url's in asp.net MVC5?

I have the following code in my View.

@model MovieApp.Models.HomeIndexViewModel
@foreach (var item in Model.Movies)
{
<div class="container">
<div class="row">
<div class="col-xs-4">
<img src=item.posterPath id="picture1" class="img-responsive" />
</div>
</div>
</div>
}


I retrieve the image Url's on item.Posterpath as a string.

When I try to add my Url's on item.PosterPath as
<img src=item.posterPath id="picture1" class="img-responsive"/>
I can see that the item is not in scope.
My question is how i should iterate over my Model to stay in the scope and retrieve my paths?

Answer

have you tried src="@item.posterPath" ?