本地化路线解决方案

发布于 2024-12-06 13:13:37 字数 721 浏览 0 评论 0原文

我构建了一个法语/英语应用程序,我想对两种语言使用相同的控制器/视图,但有一个映射到当前语言的不同路线。假设我有 website.com/Account/Register 返回到我的帐户控制器和注册操作,我希望有一个 website.com/Comptes/Inscription 路由>。我知道我可以在 RegisterRoute 部分中添加自定义路由,如下所示:

routes.MapRoute(
                "AccountFr", // Route name
                "comptes/inscription", // URL with parameters
                new { controller = "Account", action = "Register" } // Parameter defaults
            );

但是它需要大量[无聊]代码来编写所有可能的路由,而且,我认为当我将 T4MVC 用作 < code>@Url.Action(MVC.Account.Register()) 无论我使用法语还是英语,都会返回 /Account/Register 。

有人对这个问题有建议/想法吗?

谢谢!

编辑

由于使用 T4MVC 似乎没有一个好的解决方案,是否有人有其他好的解决方案?

I built a french/english app and I would like to use the same controller/view for both language but to have a different route that is map to the current language. Let say I have website.com/Account/Register that return to my Account controller and Register action, I would love to have a route that is website.com/Comptes/Inscription. I know that I can add a custom route in the RegisterRoute section like so :

routes.MapRoute(
                "AccountFr", // Route name
                "comptes/inscription", // URL with parameters
                new { controller = "Account", action = "Register" } // Parameter defaults
            );

But it will need a lot of [boring] code to write all the possibles routes and also, I think it won't work when I will use T4MVC as @Url.Action(MVC.Account.Register()) will return /Account/Register no mater if I'm in french or in english.

Anyone as suggestions/ideas for this problem?

Thanks!

EDIT

Since it does not seem to have a good solution using T4MVC does anyone have an other good solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

夜唯美灬不弃 2024-12-13 13:13:37

不幸的是,这对于 T4MVC 来说并不容易。问题的根源在于,当通过T4MVC时,你无法选择特定的路线。相反,路线是根据控制器、操作和参数来选择的。

Unfortunately, this won't easily work with T4MVC. The root of the problem is that when going through T4MVC, you can't pick a specific route. Instead, the route gets selected based on the Controller, action and parameters.

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