在 JQuery 中获取本地化语言

发布于 2024-12-27 07:32:29 字数 336 浏览 3 评论 0原文

我通过使用以下格式的 URL 在我的网站中显示和确定所选语言:

/{languageCode}/Area/Controller/Action

在我的 C# 中,当我需要查找语言代码时,我使用此语法:

RouteData.Values["languageCode"]

但是,当我需要使用 JQuery 调用操作时,如何做我确定语言代码,以便可以调用正确的路线,即 en-US/Area/Controller/Action ?我不知道如何在客户端 Javascript 中访问此信息。有人可以帮忙吗?

I am displaying and determining the selected language in my website by using URLs in this format :

/{languageCode}/Area/Controller/Action

And in my C# when I need to find the language Code I am using this syntax :

RouteData.Values["languageCode"]

However, when I need to call an action using JQuery, how do I determine the language code so that I can call the correct route i.e. en-US/Area/Controller/Action ? I don't know how to access this information in my client side Javascript. Can anybody help?

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

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

发布评论

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

评论(2

猛虎独行 2025-01-03 07:32:29

因为您的 URL 有语言代码。如何使用

window.location

https://developer.mozilla.org/en/DOM/window.location< /a>

然后从 url 中提取语言。也许是这样的:

var url = "example.com/en-us/Area/Controller/Action"; //or window.location:
var lang = url.split("/")[1];

不需要使用 JQuery! :)

Since your URL has the language code. How about using

window.location

https://developer.mozilla.org/en/DOM/window.location

And then extract the language from the url. Maybe something like:

var url = "example.com/en-us/Area/Controller/Action"; //or window.location:
var lang = url.split("/")[1];

No need to use JQuery! :)

网名女生简单气质 2025-01-03 07:32:29

您可以在服务器端发出它,例如:

var url = '@Url.Action("Action", routeValues)';

You could emit it, server-side, e.g.:

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