Tuesday, July 7, 2009

RouteLink and ActionLink in ASP.NET MVC

For some reason this took me some time to understand.

RouteLink() has 10 overloads. For some reason I couldn't understand that RouteLink went back to the routes.MapRoute() that you originally setup in the global.asax.cs file. That I understand now. The overload that I am currently using the most is:

string HtmlHelper.RouteLink(string linkText, string routeName, string routeValues);

e.g.:

RouteLink("Text that will appear on page", "First param in MapRoute()", new { controller = "Home", action = "Index", id = Model.ID })

ActionLink() on the other hand, I'm now using to route to another action on that same controller or the same action with different parameters.

6 comments:

  1. Hi Ellis, thanks for the short and straight to the point answer. Your post was a solution to what I was really struggling to understand. Looking forward to more of your posts :).

    ReplyDelete
  2. Thanks. Saved my day.

    ReplyDelete
  3. Thanks. Now, i understand the difference between the two better.

    ReplyDelete
  4. Disapointing....
    I was hoping to find a bit more detail on what were the differences of each Helper method between ActionLink and RouteLink and when you should use one or the other.

    ReplyDelete
  5. To the point explanation. Simple yet very powerful.
    Thanks

    ReplyDelete
  6. Great explanation! Thanks for share it!

    ReplyDelete