我是捆绑和优化的新手,并试图理解。 我正在包含 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 - 在 scriptmanager 中注册 "jqgrid"的 bundle ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26278840/