本地化路线解决方案
我构建了一个法语/英语应用程序,我想对两种语言使用相同的控制器/视图,但有一个映射到当前语言的不同路线。假设我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,这对于 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.