I have a page where I want to include a “Home” link which takes me to my application’s base URL. So far the simplest way I managed to achieve this is through the following line of Razor code, but it’s not pretty and I’m not terribly confident about it:
@Html.RouteLink(MyResources.HomeLinkLabel, new { controller = "" })
Note that if I don’t include controller = "" then the hyperlink it generates takes me to the current page, not my base URL.
I feel I’m missing something obvious… What’s the correct way of doing this?
You could use the following code to get the root URL
The server-side
~/syntax references the root of your application (meaning it will take into account if your app is registered in a virtual path in IIS).