如何在JS文件中获取资源(.resx)字符串



我正在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

感谢:)

最新更新