MVC3 语言路线/常量覆盖?
假定定义了以下两条路由:
routes.MapRoute(name: "StateResultsCategory", url: "{state}/{category}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateCategory" });
routes.MapRoute(name: "FRStateResults", url: "fr/{state}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateFR" });
第一条路由是捕获“fr”并将其传递给“fr”的错误操作。
我不想对第一条路线设置限制,因为我以后可能会有其他特定于语言的路线。 IE。
routes.MapRoute(name: "CHStateResults", url: "ch/{state}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateCH" });
routes.MapRoute(name: "SPStateResults", url: "sp/{state}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateSP" });
我如何设置路线来适应这种情况?
谢谢。
Given the following two routes defined:
routes.MapRoute(name: "StateResultsCategory", url: "{state}/{category}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateCategory" });
routes.MapRoute(name: "FRStateResults", url: "fr/{state}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateFR" });
The first route is trapping the "fr" and passing that off to the wrong action for "fr".
I don't want to set a constraint on the first route, as I may later have other language-specific routes. ie.
routes.MapRoute(name: "CHStateResults", url: "ch/{state}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateCH" });
routes.MapRoute(name: "SPStateResults", url: "sp/{state}/{searchTerm}", defaults: new { controller = "Results", action = "SearchStateSP" });
How do I setup the routes to accomodate this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您放置路线的顺序会有所不同。
将更具体的路线放在更通用的路线之上,可确保它们不会陷入更通用的版本中。
The order in which you place your routes makes a difference.
Placing your more specific routes above the more generic routes ensures they won't get caught up in the more generic version.