ASP MVC 2 通过 url 更改语言
我正在尝试为具有两种或多种语言的网站创建语言切换。
当我遵循默认路由(控制器/操作)时, Html.ActionLink("NL", ViewContext.RouteData.Values["action"].ToString(), new { language = "nl-NL" }, null )
确实有效。但是,当从带有参数的操作调用时,它(逻辑上)仅创建到具有当前操作的控制器的链接。参数被忽略。
我当前的路线:
routes.MapRoute(
"ProjectCategory",
"{language}/Projects/{action}/{slug}",
new { controller = "Projects", action = "Detail", slug = string.Empty, language = "en-US" }
);
使用Html.ActionLink
创建的链接:
http://localhost/mysite/nl-NL/Projects/Detail/
如何解决这个问题?
I'm trying to create a languageswitch for a website with 2 or more languages.
When I follow the default route (controller/action) the Html.ActionLink("NL", ViewContext.RouteData.Values["action"].ToString(), new { language = "nl-NL" }, null)
does it's work. But when called from an Action with parameters, it (logically) only creates a link to the Controller with the current Action. The parameters are ignored.
My current route:
routes.MapRoute(
"ProjectCategory",
"{language}/Projects/{action}/{slug}",
new { controller = "Projects", action = "Detail", slug = string.Empty, language = "en-US" }
);
The link created with Html.ActionLink
:
http://localhost/mysite/nl-NL/Projects/Detail/
How to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是最优雅的方式,但对我有用。 (当然,您应该将
en-US
替换为当前的语言)It's not the most elegant way, but works for me. (Of course you should replace
en-US
with the current lang)