Last post Sep 25, 2009 12:13 AM by hasselhoss
Sep 24, 2009 06:26 PM|crawford.r|LINK
I'm confused about the way this helper works, or why it works this way... In the various overlaods, there are ones that take Text, ActionName, RouteValues, and HtmlAttributes. If you are supplying the RouteValues, why would you also supply the ActionName
separately? Isn't the Action one of the things you can provide in RouteValues?
Sep 24, 2009 11:58 PM|jeloff|LINK
Yes, but it does offer some additional benefits. You could have a fixed set of route values that are reused in your code, but only want to override the actionName in specific instances.
actionName and controllerName are the values most likely to be used for simple applications. Once you start using custom routes, it may become necessary to include the routeValues and since many of the overloads specify parameters of type object it easier
to choose the correct overload so it's somewhat necessary to provide users with a broad range of options.
For example, if we only had
ActionLink(string linkText, string actionName) and ActionLink(string linkText, object routeValues) then it's easy to choose the wrong overload if you wrote something like ActionLink("Foo", null);
Also, many helpers including ActionLink and RouteLink work through a central mechanism that applies a set of rules that determines how explicit parameters, user supplied dictionaries and implicit values are merged to ensure consistent behavior throughout
Sep 25, 2009 12:13 AM|hasselhoss|LINK
There is also the RouteLink html helper. You can use Html.ActionLink when you care about actions and Html.RouteLink when when you're concerned with specifying a route.