2013-04-26 40 views
5

我有script.js文件,其中包含幾個字符串在西里爾文。當我試圖用這樣的非標準鏈接加載此:如何在MVC ScriptBundle中將charset設置爲.js文件?

<script type="text/javascript" src="~/Content/Script/Script.js"></script> 

西裏爾字母成爲rectangulars/badCharsetCaracters。

這解決了broblem:

<script type="text/javascript" src="~/Content/Script/Script.js" charset="windows-1251"></script>

如何設置字符集與ASP.NET MVC 4個捆綁包?像這樣的代碼:

bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
        "~/Content/Script/Script.js")); 

回答

10

可以使用Scripts.RenderFormat指定自定義腳本標籤渲染格式:

@Scripts.RenderFormat(
    "<script type=\"text/javascript\" src=\"{0}\" charset=\"windows-1251\"></script>", 
    "~/bundles/scripts") 
2

更改腳本文件的編碼到您的網站的編碼。

例如,如果您的網站是UTF-8,然後編碼:

  1. 打開腳本文件在Windows的記事本
  2. 單擊文件>另存爲
  3. 更改編碼UTF- 8(編碼列表在「保存」按鈕前面)
相關問題