【发布时间】:2013-03-15 14:16:47
【问题描述】:
当我在 MVC 4 中使用下面的 Bundling 时,我的 App 出现了几个 JavaScript 错误,例如 'jQuery undefined'
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
但是当我使用下面的方法时,我的应用程序没有 JavaScript 错误:
bundles.Add(new ScriptBundle("~/bundles/jquery1").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery2").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery3").Include(
"~/Scripts/jquery.unobtrusive*"));
bundles.Add(new ScriptBundle("~/bundles/jquery3").Include(
"~/Scripts/jquery.validate*"));
我的问题:有什么问题?
【问题讨论】:
-
在调试模式下,各个脚本标签的添加顺序是否正确?
-
听起来脚本包含在错误的顺序中。这个答案表明它可能是您正在使用的 Web 优化框架的版本:stackoverflow.com/a/11995916/1043198
-
@AntP 非常感谢,我更新到 Microsoft.AspNet.Web.Optimization 版本 1.1.0-Beta1 现在我的应用程序可以正常工作了。
-
@user197508 我已将我的回复作为答案发布:)
-
@AntP 谢谢;)我接受了你的回答,+1 票。
标签: asp.net asp.net-mvc asp.net-mvc-4 bundling-and-minification system.web.optimization