Can I send optional parameters (empty strings, null int?'s etc) to an action through a GET request in asp.net mvc? (one sentence question!)
+1
A:
You can do optional parameters with the routing table fairly easily, just specify the defaults in the route of the global.cs file.
So for a search page with an optional query and page you would have something like
RouteTable.Routes.Add(new Route
{
Url = "Search/[query]/[page]",
Defaults = new { controller="Search", action="Results", page=1 },
RouteHandler = typeof(MvcRouteHandler)
});
Default page for your search is then 1.
Odd
2008-11-20 02:07:52
+1 exactly what I was going to say
Robert Gould
2008-11-20 02:22:09
Yes, but how about my search url that has about 15 optional parameters. And optional doesn't mean with a default, it means optional.I could off course agree on a certain term that my controller then discards when found.
borisCallens
2008-11-20 08:32:52