MVC3 语言路线/常量覆盖?

发布于 2024-11-14 20:53:00 字数 776 浏览 4 评论 0原文

假定定义了以下两条路由:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜清冷一曲。 2024-11-21 20:53:00

您放置路线的顺序会有所不同。

将更具体的路线放在更通用的路线之上,可确保它们不会陷入更通用的版本中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文