我正在使用多语言
开发应用程序MVC 5
,并且我的xyz.js
文件中有一些函数,但我没有知道如何获取 .js
文件中的资源字符串。我在网上进行了很多探索,但无法找到合适的答案。请帮我解决这个问题。
提前致谢。
最佳答案
我已经解决了这个问题。我在我的 Controller 中创建了一个方法,它将从资源文件中获取资源字符串,并在我的 js 文件中进一步使用该字符串。
public JsonResult GetResourceString(string labelName)
{
string result ="";
result = ResourceMessage.ResourceManager.GetString(labelName);
if (Request.Cookies["culture"].Value == "th")
{
cul = CultureInfo.CreateSpecificCulture("th");
result = ResourceMessage.ResourceManager.GetString(labelName,cul);
}
return Json(new
{
message = result
}, JsonRequestBehavior.AllowGet);
}
上述方法将获取资源字符串,然后您可以使用它。
这里 ResourceMessage
是我的资源文件名,cul 是 CultuerInfo
。
谢谢:)
关于javascript - 如何获取JS文件中的资源(.resx)字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37267297/