我有一个名为 Image 的自定义助手类,它有两个参数:
现在我要在其中一个 View 中调用它,
@Html.Image("../Images/Indian.gif","Image is not supported or exist")
<img src="~/Images/Indian.gif" alt="Image is not supported or exist" />
现在,这两者都会给我相同的结果,但我很困惑,为什么两者的路径都不相同以及“../path”和“~/path”表示什么?
当我在 Web 浏览器中检查元素时,它会生成以下两行:
<img alt="Image is not supported or exist" src="../Images/Indian.gif" />
<img src="/Images/Indian.gif" alt="Image is not supported or exist" />
最佳答案
In ASP.NET, the tilde
(~)
refers to the application root directory. On the other hand, Two dots(..)
refers to the folder that is one level higher than the current folder.
刚用时
../
相对于 Web 服务器的常规路径。意味着从当前位置向上走一条路径(请记住:. = This location | .. = Up a directory
)。~
字符提供虚拟路径并引用网站的根目录。
关于asp.net-mvc - MVC 中 ../path 和 ~/path 表示什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43735333/