我在ASP MVC 4网站上使用以下BundleCollection
项目(第一次使用MVC 4)。我试图加载jQuery和Backbone.js,但根据Chrome的控制台,这是正常的。
以下是我现在正在使用的.js文件。当我第一次加载页面时,我收到以下错误
如果我注释掉那一行,那么我就会在下一行收到此错误
这似乎告诉我,即使我没有收到任何错误,Backbone和jQuery也没有正确加载(尽管我可能错了)。
BundleConfig
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/BackboneApps").Include(
"~/Scripts/SliderApp.js"));
bundles.Add(new ScriptBundle("~/bundles/jsMVC").Include(
"~/Scripts/underscore.js",
"~/Scripts/backbone.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
Layout.cshtml
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jsMVC")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/BackboneApps")
</head>
Index.cshtml
<h3>SPX Allocation: <span id="SpxAllocPercentage"></span></h3>
<!-- "slider" is a jquery slider -->
<div id="slider"></div>
<!-- "sliderVal" displays the slider's position. It receives the value via model. -->
<input type="text" id="sliderVal" value="0"/>
修改
这是呈现的HTML。立即注意到Backbone丢失了。
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title></title>
<link href="/Content/site.css" rel="stylesheet"/>
<script src="/Scripts/jquery-1.8.2.js"></script>
<script src="/Scripts/jquery-ui-1.8.24.js"></script>
<script src="/Scripts/SliderApp.js"></script>
</head>
当我再次检查控制台时,似乎我错了,有关Backbone和Underscore的这两个错误
答案 0 :(得分:1)
如果任何其他包包含jquery(定义了两次),则可能会看到这样的错误。首先加载一个包,然后查看页面源以验证包中的文件是否已包含在内。对每个重复,直到一个包加载丢失的文件。