2

I'm having database table which include the urls of images..I tried to retrieve them and display in the cshtml page.But it doesn't display the images.But the Names of each photo is displayed.why is that??

 @foreach (var item in Model)
{
  <img class="img-responsive" src="@item.Image" alt="" style="width:200px;height:200px" />
<h4 class="centered">@item.Name</h4>
}

in the Image column in the table, urls are stored as;

ex:
~/Images/Objects/fitem10.jpg

1
  • Is image available at that location? If you check generated HTML source what is the value of SRC tag coming out? Is relative path correct? Commented Feb 16, 2015 at 7:16

1 Answer 1

3

You need to set the src property of the image:

<img src= "@Url.Content(item.Image)" alt="alternative text" />

Url.Content() resolves the relative path of the image into an absolute path for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.