在 ASP.NET MVC 5 Server.MapPath() 中返回带有双反斜杠的路径

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

在 ASP.NET MVC 5 中,Server.MapPath() 返回带有双反斜杠的路径和添加到我的物理项目的图像文件 "~/Images/" folder.But 它没有显示在我的解决方案资源管理器中即使在 refresh.I 已经尝试 Replace() "\" 和 "/" 但它不起作用。现在无法显示图像。

我的图片文件夹路径:"~/Images" 数据库中的图像路径另存为:"D:\ProjectName\SolutionFolder\Images\Image1.jpg"

请帮我解决这个问题...

您需要像这样在 asp.net Razor 视图中显示图像:

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

并且没有必要使用磁盘位置(Server.MapPath()将return磁盘位置指定为特定路径,非常危险)


更新:

这是 link 来自 Asp.net 网站的一个关于如何使用图像的有用信息:

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