ASP.Net MVC RC1 RouteCollection.MapRoute 问题
我对 ASP.Net MVC 的 RC1 版本有疑问。 每当我在“默认”路由之前添加路由时,创建的结果 URL 都是针对添加的第一个路由。
这是我在 Global.asax.cs 中的路由,
routes.MapRoute(
"product-detailed",
"Products/{controller}/{action}/{id}",
new { controller = "ProductSubType", action = "Index", id = "" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
我的 Url 创建:
<%= Html.ActionLink("Bikes", "Index", "Bikes") %><br />
<%= Html.RouteLink("Bikes", "product-detailed", new { controller = "Bikes", action = "Index" }) %>
我希望第一个 ActionLink 创建一个像“/Bikes/Index”这样的 Url,第二个 RouteLink 创建“/Products/Bikes/Index”,但是两个 URL 都结束为“/产品/自行车/索引”。
我在路由中缺少什么?
谢谢。
I have a problem with the RC1 version of ASP.Net MVC. Whenever I add a Route before the "Default" route, the resulting Urls created are for the first Route added.
Here is my Routing in Global.asax.cs
routes.MapRoute(
"product-detailed",
"Products/{controller}/{action}/{id}",
new { controller = "ProductSubType", action = "Index", id = "" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
My Url creation:
<%= Html.ActionLink("Bikes", "Index", "Bikes") %><br />
<%= Html.RouteLink("Bikes", "product-detailed", new { controller = "Bikes", action = "Index" }) %>
I would expect the first ActionLink to create a Url like "/Bikes/Index" and the second RouteLink to create "/Products/Bikes/Index", but both Urls end up as "/Products/Bikes/Index".
What am I missing here on the routing?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你没有遗漏任何东西。 它按设计工作。
由于控制器和操作在顶部路由中都是变量,并且对有效值没有限制,因此该路由对于控制器和操作的所有值都有效。
潜在的解决方法:
You're not missing anything. It's working as designed.
Since the controller and action are both variable in the top route, with no limitations on valid values, then that route is valid for all values of controller and action.
Potential work-arounds: