我有一个包含以下路由的.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 main
此请求不工作:
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);
}发布于 2009-10-29 07:31:27
我发现一个问题,您的第二个和第三个路由具有完全相同的URL参数。所以第三个路由永远不会被调用。你怎么会把它放在那儿?看起来你可以简单地删除第二条路线。
而且,第二路由比第一路由具有更少的参数。这意味着第一个路由可能与您发布的两个URL都匹配。您可能应该对这些路由重新排序。
更新:哦!我没有注意到URL中的双斜杠。那是行不通的。就ASP.NET而言,它不是有效的URL,因此ASP.NET甚至在请求到达路由之前就阻止了它。
https://stackoverflow.com/questions/1640648
复制相似问题