It has been awhile since I worked with ASP.NET MVC due to work and many other activities, but I wanted to get back into it since I have always loved programming. One of the first issues I ran into when publishing my site was a pretty simple one, I needed to change the menu button for Home to link back to the root of the site. Very easy and basic to do, I could just hard code the root of the site into the HTML, i.e.
Or I could do it the proper MVC-way with an HTML.ActionLink:
The first way was not good since I have a couple different development environments where the root url differs in each, and it just goes against the idea of having a dynamic website when you start hard-coding things. The alternative is great, except it broke the formatting of the menu system. I could tweak the menu system to support it, but I knew there had to be a simple way to just get a relative URL path. I do it all the time in controls with "~/", so I know that in .NET the tilde (~) represents the root of the path, but I forgot how to format just a URL. Luckily a quick search lead me to Url.Content(), which "Converts a virtual (relative) path to an application absolute path":
You could even make it call an MVC view by just adding the controller and action to the relative URL: "~/Controller/Action".
In most places I would still use the Html helpers, but this is useful for when just the URL is needed. It feels good to be coding again for fun.