What does ../ path and ~ / path indicate in MVC?

I have one custom helper class called Image that has two arguments:

  • CAC

  • alto

Now I'm going to call it in one of the 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 will give me the same result, but I'm confused that the path was not the same for both and what do "../path" and "~ / path" mean?

This two line line generates when I inspect an 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" />

      

+3


source to share


1 answer


In ASP.NET, the tilde (~)

refers to the root of the application directory. On the other hand, two dots (..)

refer to a folder one level above the current folder.

When you just use ../

normal paths relative to the web server. Can travel the path from their current location (remember that:) . = This location | .. = Up a directory

.



The symbol ~

provides virtual paths and links to the root of the website.

+1


source







All Articles