【发布时间】:2013-09-23 19:04:47
【问题描述】:
这没有发生。我尝试将_Layout.cshtml中的脚本与<script src='@Content.Url("...正常链接,安装Web优化并使用捆绑包,并将@Scripts.Render()放在_Layout.cshtml的head/body/bottom和相关页面上的<script>标签之前。我错过了什么?
目录结构
Views
Shared
Js
jquery-1.10.2.js
jquery.color-2.1.2.min.js
BundleConfig.cs
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Views/Shared/Js/jquery-{version}.js",
"~/Views/Shared/Js/jquery.color-{version}.js")
);
}
Global.asax.cs
protected void Application_Start()
{
// blah, etc, then:
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
_Layout.cshtml
@Scripts.Render("~/bundles/jquery");
我可以在 JsFiddle 上运行实际的 javascript/jquery 代码,所以我在那里写的内容的有效性没有问题。
【问题讨论】:
-
直接引用 jquery 而不使用 bundler(例如来自 CDN)是否有效?
-
HTML 输出是什么样的?
-
为什么不把它们放在 Scripts 文件夹中?
-
@MichaelCwienczek 不,无论我是在 _Layout.cshtml 的头部还是在我正在使用的页面的正文中引用它们。
-
@ErikPhilips Oopes 无视我的最后回复!我看到 jquery 脚本以正确的方式链接(源路径是
Views/Shared/Js/jquery-1.10.2.js),但是在该位置找不到脚本的错误。
标签: c# jquery asp.net-mvc razor