如何在JS文件中获取资源(.resx)字符串
本文关键字:资源 resx 字符串 获取 JS 文件 | 更新日期: 2025-04-15 18:49:48
我正在multilingual
中开发应用程序MVC 5
,我的xyz.js
文件中有一些函数,但我不知道如何在.js
文件中获取资源字符串。我在网上探索了很多,但都找不到合适的答案。请帮我解决这个问题。
提前谢谢。
我已经解决了这个问题。我在我的控制器中制作了一个方法,它将从资源文件中获取资源字符串,我在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
。
感谢:)