views:

168

answers:

1

Hi All,

I have a .net mvc with the following routes:

routes.Add(new Route(
            "Lookups/{searchtype}/{inputtype}/{firstname}/{middlename}/{lastname}/{city}/{state}/{address}", 
            new RouteValueDictionary( new { controller = "Lookups", action = "Search", firstname = (string)null, middlename = (string)null, lastname = (string)null, city = (string)null, state = (string)null, address = (string)null, SearchType = SearchType.PeopleSearch, InputType = InputType.Name }),
            new MvcRouteHandler())
        );

        routes.Add(new Route(
            "Lookups/{searchtype}/{inputtype}", 
            new RouteValueDictionary( new { controller = "Lookups", action = "Search", firstname = "", middlename = "", lastname = "", city = "", state = "", address = "" }),
            new MvcRouteHandler())
        );

        routes.Add(new Route(
            "Lookups/{searchtype}/{inputtype}", 
            new RouteValueDictionary( new { controller = "Lookups", action = "Search", firstname = "", middlename = "", lastname = "", city = "", state = "", address = "", SearchType = SearchType.PeopleSearch, InputType = InputType.Name }),
            new MvcRouteHandler())
        );

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Account", action = "LogOn", id = "" }  // Parameter defaults
        );

The following request works fine:

http://localhost:2608/Lookups/PeopleSearch/Name/john/w/smith/seattle/wa/123 main

This request does not work:

http://localhost:2608/Lookups/PeopleSearch/Name/john//smith//wa/

Not all requests will have all paramters and I would like empty parameters to be passed to the method as empty string or null.

Where am I going wrong?

The method:

public ActionResult Search(string firstname, string middlename, string lastname, string city, string state, string address, SearchType searchtype, InputType inputtype)
    {
        SearchRequest r = new SearchRequest { Firstname = firstname, Middlename = middlename, Lastname = lastname, City = city, State = state, Address = address, SearchType = searchtype, InputType = inputtype };
        return View(r);
    }
+1  A: 

I see one problem, your second and third route have exactly the same URL parameters. So the third route will never get called. Why do you have that there? It looks like you could simply delete the second route.

Also, the second route has less parameters than the first route. That means the first route will probably match both the URLs that you posted. You should probably re-order those routes.

UPDATE: Oh! I didn't notice the double slash in the URL. That'll never work. It's not a valid URL as far as ASP.NET is concerned and thus ASP.NET is blocking the request even before it gets to Routing.

Haacked
In the name of simplicity I removed the second and third routes. Same result.
I'm going with standard parameters for now. I'll make the url's pretty at a later time when I'm not under a deadline.