2

我是捆綁和優化以及嘗試理解的新手。 我在網站中創建包含Webform.Net Framework 4.0。我創建了'BundleConfig.cs',其中我正在創建捆綁包。它有下面的代碼:scriptmanager中的「jqgrid」註冊包

public static void RegisterBundles(BundleCollection bundles) 
    { 
     /// JavaScript Bundles. 
     // removed other standard bundles for readability. 

     bundles.Add(new ScriptBundle("~/Bundles/jqGird") 
       .Include("~/Scripts/jquery.jqGrid.min.js") 
       .Include("~/Scripts/i18n/grid.locale-en.js") 
      ); 
    } 

我也創建 '的Global.asax',其中包含:

<script runat="server"> 
    void Application_Start(object sender, EventArgs e) 
    { 
     // Code that runs on application startup 
     // Registering Bundles 
     Sheridan.DPD.WebApp.BundleConfig.RegisterBundles(BundleTable.Bundles); 

     // Enabling Bundle Optimization. 
     BundleTable.EnableOptimizations = true; 

    } 
</script> 

現在,在母版頁我正在註冊摞 'ScritpManager'

<asp:ScriptManager runat="server" ID="scriptMgr" EnablePageMethods="true"> 
    <Scripts> 
     <%--Framework scripts--%> 
     <asp:ScriptReference Name="MsAjaxBundle" /> 
     <asp:ScriptReference Name="jquery" /> 
     <asp:ScriptReference Name="jquery.ui.combined" /> 

     <asp:ScriptReference Name="jqGird" /> 

     <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" /> 
     <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" /> 
     <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" /> 
     <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" /> 
     <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" /> 
     <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" /> 
     <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" /> 
     <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" /> 
     <asp:ScriptReference Name="WebFormsBundle" /> 
     <%--Site scripts--%> 
    </Scripts> 
</asp:ScriptManager> 

它給我下面的錯誤。

System.InvalidOperationException:'jqGird'不是有效的腳本名稱。該名稱必須以'.js'結尾。

那麼,我做錯了什麼?因爲其他Bundle工作正常。

回答

3

你需要使用ScriptManager Class

ScriptManager.ScriptResourceMapping.AddDefinition("jqGird", new ScriptResourceDefinition 
{ 
    Path = "~/Bundles/jqGird", 
}); 

到所有scripts一起註冊爲jqGird您也可以參考ASP.NET 4.5 ScriptManager Improvements in WebForms

+0

您好,感謝。我可以通過將代碼放入global.asax中的'Application_Start'來解決錯誤。 – Nishant 2014-10-10 08:48:15

+0

非常歡迎! :) – Izzy 2014-10-10 08:50:41