Search code examples
c#asp.netasp.net-mvcasp.net-mvc-5server.mappath

In ASP.NET MVC 5 Server.MapPath() returning path with double backslashes


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...


Solution

  • 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