Reputation: 474
I am working on MVC 5 ASP.net. When I am using razor syntax image is not showing on web page otherwise same hard coded value is working.
Here is the code.
@{
var path = "";
}
@foreach (Movy a in Model)
{
if (a.Image == null)
{
path = "~/Content/images/c3.jpg";
}
else
{
path = a.Image;
}
<img src="@path" />
}
but when I replace @path to "~/Content/images/c3.jpg" in source of image it works.
Upvotes: 0
Views: 222
Reputation: 19007
You need to resolve the string in run time. Use Url.Content
<img src="@Url.Content(path)" />
Upvotes: 1