asp.net - 在 scriptmanager 中注册 "jqgrid"的 bundle

标签 asp.net jqgrid asp.net-4.0 scriptmanager asp.net-optimization

我是捆绑和优化的新手,并试图理解。 我正在包含 Webform.Net Framework 4.0 的网站中创建 bundle 。我创建了“BundleConfig.cs”,我在其中创建 bundle 。它有以下代码:

 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”中注册 bundle

<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' is not a valid script name. The name must end in '.js'.

那我到底做错了什么?因为其他 bundle 工作正常。

最佳答案

您需要使用 ScriptManager Class 将所有脚本一起注册为jqGird

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

您还可以引用ASP.NET 4.5 ScriptManager Improvements in WebForms

关于asp.net - 在 scriptmanager 中注册 "jqgrid"的 bundle ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26278840/

相关文章:

asp.net - 无法在 html 中调整图像大小 (cshtml asp.net mvc 4)

compression - IIS 7.5 ASP.NET-4 Gzip压缩

asp.net - 使用 ASP.NET 4.0 和 IIS7 进行 HTTP 压缩

c# - 为什么 Visual Studio 在 Razor (.cshtml/.razor) 中突出显示双花括号?

asp.net - 将 Grunt、Bower、Gulp、NPM 与 Visual Studio 2015 结合使用用于 ASP.NET 4.5 项目

javascript - 如何更改谷歌 Material 设计折线图中的日期格式?

jquery - JqG​​rid colMoldel 格式化程序变量

jquery - jqGrid - 向每一行添加编辑按钮

javascript - jqGrid 显示/隐藏列对话框

C# 排序并放回 Regex.matches