【发布时间】:2015-09-15 20:31:47
【问题描述】:
我有一个页面应该接受两个 url,一个没有动作,应该有默认值“索引”,一个有一个应该链接到用户给定动作的动作。
链接:
- 第三方/测试/3
- 第三方/测试/索引/3
我想出了以下路线:
RouteTable.MapRoute("ThirdParty", "{thirdParty}/{controller}/{action}/{type}",
new { action = "Index" },
new { thirdParty = "^[a-zA-Z0-9]*$", type = @"\d+" },
new[] { @namespace });
不幸的是,这只匹配以下路线:
- SpamReferral/Test/Index/3
现在我已经给动作一个默认值“索引”,我认为它会匹配路由,但事实并非如此。我只是得到一个 404。
为什么它不匹配没有“索引”操作的路由? 我正在使用 ASP.NET MVC 4。
创建 2 条路线可以正常工作,但我很确定它应该可以在一条路线中使用。
RouteTable.MapRoute(name, "{thirdParty}/{controller}/{type}",
new { action = "Index"},
new { thirdParty = "^[a-zA-Z0-9]*$", type = @"\d+" },
new[] { @namespace });
RouteTable.MapRoute(name + "(2)", "{thirdParty}/{controller}/{action}/{type}",
new { action = "Index" },
new { thirdParty = "^[a-zA-Z0-9]*$", type = @"\d+"},
new[] { @namespace });
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-4 routes url-routing asp.net-mvc-routing