What's the difference between these 2 methods?
Html.ActionLink(string linkText, string actionName, object routeValues, object htmlAttributes)
Html.ActionLink(string linkText, string actionName, RouteValueDictionary routeValues, IDictionary htmlAttributes)
Yes, they have the same number of parameters. Yes, they even have the same parameter names. So in essence the intent of calling either of these methods is to build up a link with the passed in route values and HTML attributes. Yet the difference between these 2 methods couldn't be more pronounced.
Take this line of code:
@Html.ActionLink("Back to List", "Index", TempData["SavedRouteValues"], null)
What I wanted was an easy way to retain the settings of a Telerik ASP.NET MVC Grid and build up a link to bring me back to the correct state. This line of code does that. However, it generates a link similar to this (word-wrapped here for clarity):
To fix this, just use this code (a simple typecast) to force the correct overloaded method to be picked:
@Html.ActionLink("Back to List", "Index", (RouteValueDictionary)TempData["SavedRouteValues"], null)
The moral of the story? If you're an API desiger, don't make overloaded methods lightly. Make sure they add value and distinction. A strong type vs. an object reference doesn't pass that test. If you do violate that rule, however, then at least be sure that the overload fulfills the intent and implied contract of that method.