MVC 2 URL 中的多语言
我正在使用 MVC 2 构建多语言应用程序。我阅读了很多有关获取用户语言的不同方法的文章。我认为保存语言的最佳方法是将其放入 URL 中,如下所示:www.example.de/language/controller/view。
我的问题: 1.global.asax.cs应该是什么样子?我尝试设置以下内容,但它不起作用:
routes.MapRoute("Default with language", "{lang}/{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}, new { lang = "de|en" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
lang = "en",
});
例如,路线中有一个“en”,但它总是不采用Resourse.en,它只采用默认值。
- 问题:如何获取控制器当前的语言?
- 问:如何更改语言?
I'm building a multilanguage application with MVC 2. I read a lot of posts about different ways to get the user's language. I think the best way to save the language, is to put it into the URL like this: www.example.de/language/controller/view.
My questions:
1. how should global.asax.cs look? I tried it to setting something below but it did not work:
routes.MapRoute("Default with language", "{lang}/{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}, new { lang = "de|en" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
lang = "en",
});
There was a "en" for example in the route, but it always did not take the Resourse.en, it only took the default.
- Question: How to get the current language in the controller?
- Question: How to change the language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这可以帮助?
MVC 本地化路线
Maybe this can help?
MVC Localization route