У меня есть .net mvc со следующими маршрутами:
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
);
Следующий запрос работает нормально:
http://localhost:2608/Lookups/PeopleSearch/Name/john/w/smith/seattle/wa/123 основной
Этот запрос не работает:
http://localhost:2608/Lookups/PeopleSearch/Name/john//smith//wa/
Не все запросы будут иметь все параметры, и я хотел бы, чтобы пустые параметры передавались методу как пустая строка или ноль.
Где я иду не так?
Метод:
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);
}