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