【发布时间】:2019-05-07 12:43:09
【问题描述】:
我有一个 Web 窗体应用程序,我正在努力让 jquery 捆绑正常工作。
我尝试了以下代码的多种变体,还尝试使用 NuGet 包AspNet.ScriptManager.jQuery,但到目前为止没有任何效果。
问题是脚本似乎是在客户端下载的,但它不起作用:
当调用 jquery 函数时,我得到典型的“TypeError: $(...).is not a function”-error.
我在 BundleConfig.cs 中的代码:
BundleTable.EnableOptimizations = false;
bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-3.3.1.js"));
ScriptManager.ScriptResourceMapping.AddDefinition("jquery",
new ScriptResourceDefinition
{
Path = "~/bundles/jquery",
DebugPath = "~/bundles/jquery",
});
在 Site.Master 中:
<asp:ScriptManager runat="server" EnablePageMethods="True">
<Scripts>
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Path="~/Scripts/bootstrap.min.js" />
<asp:ScriptReference Name="jquery.ui.combined" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Path="~/Scripts/GlobalFunctions5.js" />
<asp:ScriptReference Path="~/Scripts/AjaxControlToolkit/Bundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
最终,我希望能够升级 jQuery NuGet 包而无需更改 BundleConfig,所以我也尝试了这个(它甚至不会在客户端加载 bunde):
bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
还有什么可能会影响捆绑 jQuery 或者我在这里做错了什么?
感谢您的帮助!
【问题讨论】:
标签: jquery asp.net bundle config