[英]How to get resource (.resx) string in JS file
I am developing an application MVC 5
in multilingual
and I have some functions in my xyz.js
file, but I don't know how to get resource string in .js
file.我正在开发一个
multilingual
应用程序MVC 5
,我的xyz.js
文件中有一些函数,但我不知道如何在.js
文件中获取资源字符串。 I have explored a lot on web but not able to find suitable answer.我在网上探索了很多,但找不到合适的答案。 Please help me out for this.
请帮我解决这个问题。
Thanks in advance.提前致谢。
I have resolved this problem.我已经解决了这个问题。 I have made a method in my controller which will get the resource string from resource file and I used that string further in my js file.
我在控制器中创建了一个方法,该方法将从资源文件中获取资源字符串,并在我的 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);
}
Above method will get resource string and then you can use it.上述方法将获取资源字符串,然后您就可以使用它了。 Here
ResourceMessage
is my resource file name and cul is CultuerInfo
.这里
ResourceMessage
是我的资源文件名, cul 是CultuerInfo
。
Thanks :)谢谢:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.