The routing I need is quite simple, I must be missing something there. As code example I put the simpler situation where I can reproduce my behavior.
You have this ActionMethod :
public ActionResult Index(string provider)
{
ViewData["Message"] = provider;
return View("Index");
}
And you have this route :
routes.MapRoute(
null,
"{controller}/{action}/{provider}",
new { controller = "Home", action = "Index", provider = "Default" }
); // Parameter defaults
You can call /Home/Index/Custom and provider will take the value "Custom"
What Route would I need if I want the url /?provider=Custom to map the provider to the parameter. I thought that would just work, because the default controller and the default action would be used, and the provider from the querystring would be used instead of the default one. but the querystring is just ignored here.
That's a problem in my situation as I have a form using HTTP GET method. The form action has to be Html.BeginForm(c=>c.Index(null)) which is resolved as / and the value of my form are added in the querystring. (the provider being a dropdown in the form)
So the url built by the form is /?abc=value&cde=value...
UPDATE
The accepted answer below (see the comments) led me to this solution:
routes.MapRoute(
"Search",
"search/",
new { controller = "Home", action = "Index" }
);
routes.MapRoute(
null,
"{controller}/{action}/{provider}",
new { controller = "Home", action = "Index", provider = "Default"}
);
And declare the form like so :
Html.BeginRouteForm("Search", FormMethod.Get){
...
}
This way, the form will work with the provider in the QueryString (when I use the named route search) but in all other case, I will use the default route. :)