我有以下途径一个.NET MVC .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/
不是所有的请求都会有所有参数,我希望空参数作为空字符串或null传递给方法。
我哪里错了?
的方法:
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);
}
如果你还没有使用它 - http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx – 2009-10-28 23:00:50
非常有帮助。谢谢 – user135498 2009-10-28 23:05:31
该工具非常棒,但它无法调试我的问题。 – user135498 2009-10-28 23:15:42