开发者

MVC 2 multilanguage in URL

I'm building a multilanguage application with MVC 2. I read a lot of posts about different way开发者_StackOverflow社区s 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.

  1. Question: How to get the current language in the controller?
  2. Question: How to change the language?


Maybe this can help?

MVC Localization route

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜