Is there any benefit to using @ Url.Content ("~")

I am new to MVC4 / razor2, and I understand that the general benefit of using @Url.Contentand @Url.Action- when changing my routing or virtual directory magic-url-lines are displayed correctly.

I am looking at some inherited Javascript-with-razor code in the view that is being applied to '@Url.Content("~")'. This is displayed as the '/'- or, root of the site. What ... would always be like that, no?

Or is there some kind of situation in which this can be done differently?

Note: this is not ~/ just a single tilde.


I plan to extract razor calls to helper functions and move the main JavaScript block to an external file (for lithiation and overall "cleanliness"). I don’t need to “fix” everything that is currently happening, but I would like to better understand it.

+4
source share
2 answers

Url.Content maps the tilde to the root of the application. The root of the application does not match the root of the website.

From this article http://msdn.microsoft.com/en-us/library/system.web.virtualpathutility(v=vs.110).aspx :

(/). , (~) (~ \) (~/). , .

MVC4 Url.Content applicaiton: http://beletsky.net/2012/04/new-in-aspnet-mvc4-razor-changes.html

+10

, , .

@Url.Content()

Razor 2 .

( ):

<a href="@Url.Content("~")">Root</a>

<a href="~">Root</a>

-

~ (tidle)

slash (/) vs tilde slash (~/) asp.net

+2

All Articles