August 2008 Entries
Passing a querystring to a named route in ASP.NET MVC is not well documented.
I stumbled across this by mistake! Using either the Html.RouteLink extention or the RedirectToRoute method it is possible to pass any number of querystring parameters to the route.
All you have to do is pass the parameter in the RouteValueDictionary. For it to appear on the querystring the parameter name must not appear on the named route in the RouteCollection.
This is easier to explain in code!
Route (in Global.ascx.cs):
routes.MapRoute(
"Default",
"{controller}/{action}/{id}"
);
using Html.RouteLink:
<%= Html.RouteLink("Click Me!", "Default", new { controller = "Home",...