What’s the best option for generating links using helpers in ASP.NET MVC 3?
As far as I can see it’s better to use Url.RouteUrl and Html.RouteLink helpers than Url.Action and Html.ActionLink to generate links because the first two allow you to use RouteName instead of Controller and Action for url pattern matching.
What does best mean in this context?
Does it mean:
Because there are so many ways to make links, and each method has a different purpose, I use all of them at different times, but I normally just wrap the link in a
HtmlHelpermethod and create a strong name for it:Then you call call this as follows:
If you prefer to have a whole link generated for you (probably because you don’t have specialized CSS classes for individual links), then you could use this:
Using HtmlHelpers and UrlHelpers gives you the following advantages:
Html.and all of your links show up, especially if you putGenerateas the prefix to generate links and URLsUrlHelperswhen you just need something to build a URLI go into this at length in a blog post I wrote where I listed some tips for writing URLs in ASP.NET MVC.