../path 和 ~/path 在 MVC 中表示什么?
What ../path and ~/path Indicates in MVC?
我有一个名为 Image 的自定义助手 class,它有两个参数:
src
alt
现在我将在其中一个视图中调用它,
@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”表示什么?
当我在网络浏览器中检查元素时生成的这两行代码:
<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.
当您仅使用 ../
相对于网络的常规路径时 server.Means 从当前位置向上移动路径(记住:. = This location | .. = Up a directory
)。
~
字符提供虚拟路径并引用网站的根目录。
我有一个名为 Image 的自定义助手 class,它有两个参数:
src
alt
现在我将在其中一个视图中调用它,
@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”表示什么?
当我在网络浏览器中检查元素时生成的这两行代码:
<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.
当您仅使用 ../
相对于网络的常规路径时 server.Means 从当前位置向上移动路径(记住:. = This location | .. = Up a directory
)。
~
字符提供虚拟路径并引用网站的根目录。