-1

In ASP.NET MVC 5, Server.MapPath() returning path with double backslashes and image file adding to my physical project "~/Images/" folder.But it is not displaying in my solution explorer even after refresh.I have tried Replace() "\" with "/" but it doesn't works. unable to display images now.

My Images Folder path:"~/Images" Image Path in Database saving as : "D:\\ProjectName\\SolutionFolder\\Images\\Image1.jpg"

Please help me out of this...

Imran Sh
  • 1,623
  • 4
  • 27
  • 50
Praveen Patel G
  • 342
  • 4
  • 13
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [How to Ask](http://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – Nkosi Sep 10 '16 at 11:44
  • Why display image? When do you use it? – Imran Sh Sep 10 '16 at 11:50
  • 2
    The problem is not the double backslashes, that's the inspector escaping strings for you. The problem is using absolute file paths on a web page, that's not going to work. – CodeCaster Sep 10 '16 at 13:28

1 Answers1

2

You need to show images in asp.net Razor view like this:

<img src="~/images/Image1.jpg" />

And there is no need to use disk location (Server.MapPath() will return disk location of a specific path and is very dangerous)


UPDATE:

This is a useful link from Asp.net site about how to use images:

http://www.asp.net/web-pages/overview/ui-layouts-and-themes/9-working-with-images

Imran Sh
  • 1,623
  • 4
  • 27
  • 50
  • Hi @Author if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Imran Sh Sep 10 '16 at 12:20