0

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);
    }
4
  • 2
    In case you aren't using it yet - haacked.com/archive/2008/03/13/url-routing-debugger.aspx Commented Oct 28, 2009 at 23:00
  • The tool was great but it wasn't able to debug my problem. Commented Oct 28, 2009 at 23:15
  • What did you expect to happen? What actually happens? What does the method look like? Commented Oct 28, 2009 at 23:29
  • The debugger is never invoked because the routing engine doesn't recognize the request. It simply returns "Bad request" assumingly because of the consecutive //. What do I want to happen? - If a request doesn't contain all parameters then I want empty string or null to be passed into the method. I added the method to the post. Commented Oct 28, 2009 at 23:59

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.