【发布时间】:2017-06-22 02:35:22
【问题描述】:
我正在使用 ASP.NET MVC4...开箱即用的 _Layout.cshtml 有
@Scripts.Render("~/bundles/jquery")
在里面。我也有股票 BundleConfig.cs 有一个
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
在里面。我的 Index.cshtml 中有一个这样的脚本块,它只是一个普通视图。
<script src="@Url.Content("~/Scripts/ProductsIndex.js")" type="text/javascript"></script>
但是该脚本中的 JQuery 没有运行...但是,如果我将以下行放在我的 Index.cshtml 中(紧邻 ProductsIndex.js 脚本参考),那么 JQuery 运行良好。
<script src="@Url.Content("~/Scripts/jquery-1.8.2.min.js")" type="text/javascript"> </script>
我知道这很简单,但是鉴于 _Layout.cshtml 已经引用了 JQuery 库,我是否应该能够使用 JQuery 而无需将它再次显式添加到我的 Index.cshtml 中?
【问题讨论】:
-
检查生成的 HTML(查看源代码)以确保在您的
ProductsIndex.js之前加载 jquery。
标签: jquery asp.net-mvc-4