Usama Saleem
Usama Saleem

Reputation: 474

Image Not Displaying On Page

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

Answers (2)

Niraj Rajpurohit
Niraj Rajpurohit

Reputation: 34

Try This :

  <img src= "@Url.Content(path)" alt="Image" />

Upvotes: 0

Rajshekar Reddy
Rajshekar Reddy

Reputation: 19007

You need to resolve the string in run time. Use Url.Content

<img src="@Url.Content(path)" />

Upvotes: 1

Related Questions