0
我在我的ASP MVC 4站點(第一次使用MVC 4)上使用以下BundleCollection
項目。我試圖加載jQuery和Backbone.js,但根據Chrome的控制檯,這是正常工作。BundleConfig腳本不起作用
下面是我現在使用的.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>
當我再次檢查了控制檯,看來我錯了,有這兩個錯誤關於骨幹,並強調
請注意捆綁,以確保每個文件都以';'結尾,並可能有換行符。過去我曾遇到過將文件簡單連接在一起的問題。如果一個命令的結尾符合另一個命令的開頭,則會出現像這樣的奇怪錯誤。 – 2014-09-10 21:01:18
我也考慮jslinting你的文件,看看有沒有其他的javascript錯誤 – drneel 2014-09-10 21:03:11
@RoryMcCrossan我剛剛注意到Backbone/Underscore從呈現的HTML中缺失。更新了帖子。 – NealR 2014-09-10 21:12:28