inbound/outbound url routing in asp.net MVC
        Posted  
        
            by Stephane
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Stephane
        
        
        
        Published on 2010-06-07T15:35:48Z
        Indexed on 
            2010/06/07
            16:02 UTC
        
        
        Read the original article
        Hit count: 512
        
asp.net-mvc
|routing
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...
© Stack Overflow or respective owner