我有以下途徑一個.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