簡體   English   中英

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

[英]How to get resource (.resx) string in JS file

我正在開發一個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

謝謝:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM