【发布时间】:2011-10-25 07:03:00
【问题描述】:
我正在尝试在 MVC3 中设置与旧版 (SP 2007) 系统匹配的路由方案。这些是我设置的路线:
routes.MapRoute("administration",
"Administration/{action}/{id}",
new { controller = "Administration", action = "Index", id = UrlParameter.Optional });
routes.MapRoute("workOrderSearch",
"WorkOrderSearch",
new {controller = "Home", action = "WorkOrderSearch"});
routes.MapRoute("customers",
"{customerNumber}/{action}",
new {controller = "customer", action = "Index"},
new {customerNumber = @"\d*"});
routes.MapRoute("graphicNames",
"{customerNumber}/{graphicNameId}/{action}/{id}",
new {controller="GraphicName", action="Index", id=UrlParameter.Optional},
new {customerNumber = @"\d*",graphicNameId = @"\d*", action=@"\w*"});
routes.MapRoute("workOrders",
"{customerNumber}/{graphicNameId}/{graphicNumber}/WorkOrder/{action}/{id}",
new { controller = "WorkOrder", action = "Index", id = UrlParameter.Optional },
new { graphicNameId = @"\d*", graphicNumber = @"\d*-\d*" });
routes.MapRoute("graphics",
"{customerNumber}/{graphicNameId}/{graphicNumber}/{action}",
new { controller = "Graphic", action = "Index", id = UrlParameter.Optional },
new { graphicNameId = @"\d*", graphicNumber = @"\d*-\d*" });
routes.MapRoute("Default", "", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
它大多工作得很好。但是,当尝试使用“graphicNames”路线时,我遇到了问题。如果我使用这个网址:
http://localhost:1234/1234/321/Index
它工作正常,我得到了 GraphicName 控制器上的 Index 操作。但是,如果我这样做:
http://localhost:1234/1234/321
我得到一个 404。
所有其他路线似乎都按预期工作。
编辑:解决方案是向客户的路线添加一个约束,以便操作仅是 'action=@"[A-Za-z]*"
【问题讨论】:
-
在请求中添加一个斜杠......它有效吗?
-
不,末尾的斜杠没有帮助。
标签: asp.net-mvc-3 asp.net-mvc-routing