问题
I have one custom helper class called Image which is having two arguments:
src
alt
Now I am going to call that in one of View,
@Html.Image("../Images/Indian.gif","Image is not supported or exist")
<img src="~/Images/Indian.gif" alt="Image is not supported or exist" />
Now, this both will give me same result but I am confused that why the path was not the same for both and what "../path" and "~/path" indicate?
This two-line it generates when I do inspect element in a web browser:
<img alt="Image is not supported or exist" src="../Images/Indian.gif" />
<img src="/Images/Indian.gif" alt="Image is not supported or exist" />
回答1:
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.
When you just use ../
regular paths relative to the web server.Means go up a path from current location (Remember that : . = This location | .. = Up a directory
).
The ~
character provide virtual paths and refer to the root of the website.
来源:https://stackoverflow.com/questions/43735333/what-path-and-path-indicates-in-mvc