3

In view I want to show image which is store in view folder named Errorpage.png. Now, I want to show that image in Error.cshtml view file.

Here is my code

<img src="~/Views/Errorpage.png" alt="error">

Now , this code is not working and showing error alt in the place of image. While the path is perfectly right, but surprised that why it is not working.

While I tried by fetch the online image and that is work.

Here is the code

<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/anton-ploom.jpg" 
    alt="A danseur in brisé (a leap with the legs together) on a blue background">

Now, I am confused that this second code is working properly while the first code is not working.

The syntax is same both of the code.

Thank You.

s.k.Soni
  • 1,139
  • 1
  • 19
  • 37

3 Answers3

5

Try with this way:

can you please put your image in image folder outside Views folder that can work

or

  <img alt="error" src="@Url.Content("/Views/Errorpage.png")" />

if that doesn't work you could try with this way:

<img alt="error" src="/Views/Errorpage.png" /> 

or there is another solution if all are fails :

<img alt="error" src="<%= Url.Content("~/Views/Errorpage.png") %>" />
Vishvadeep singh
  • 1,624
  • 1
  • 19
  • 31
0

in visual studio, the image works from ~/contents/*.jpeg directory. if you will put it in any other directory it will not work.

  • 1
    Welcome to SO! Please read the [tour](https://stackoverflow.com/tour), and [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – Tomer Shetah Oct 14 '20 at 13:36
0

try this

 <img  src="@Url.Content("~/Views/Errorpage.png")"  alt="error"/>