@hutchonoid sort of touched on this, but virtual paths are just one part of the benefit. While the default route pattern is controller/action/id?
, it doesn't have to be that way. Especially if you're using attribute routing in MVC5+, the URL could be literally anything, and may not even include the controller or action name.
By handling all your links using Url.Action
or Html.ActionLink
, you abstract the view's knowledge of the URL, which is a very good thing. True separation of concerns, which is fundamental to MVC, requires pieces to be as "dumb" as possible, only knowing or caring about the things that it needs to.
If you do end up using attribute routing, I would go a step further and actually recommend naming all your routes, and then using Url.RouteUrl
/Html.RouteLink
instead of the action-centric versions. This provides even greater abstraction, as you could then have a completely different action or even controller handle that named route, without changing any of your views. You could also technically do this with standard routing, but naming routes with standard routing would require you to manually define each route, instead of relying on a default route or set of default routes.