Asp.net mvc 4 视图中的MVC4绑定和引用jquery
当jquery被捆绑并加载到_layout.cshtml中时,为什么我仍然需要在我的视图页面中引用它 如果我没有在我的视图页面中引用jquery.js文件,我的jquery将无法工作Asp.net mvc 4 视图中的MVC4绑定和引用jquery,asp.net-mvc-4,Asp.net Mvc 4,当jquery被捆绑并加载到_layout.cshtml中时,为什么我仍然需要在我的视图页面中引用它 如果我没有在我的视图页面中引用jquery.js文件,我的jquery将无法工作 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/Scripts/Bootstrap").Include(
"~/Scripts/jquery-1.*",
"~/Scripts/Bootstrap.js",
"~/Scripts/bootstrap-modalmanager.js",
"~/Scripts/bootstrap-modal.js"));
bundles.Add(new StyleBundle("~/Content/Bootstrap").Include(
"~/Content/Site.css",
"~/Content/Bootstrap.min.css",
"~/Content/Bootstrap-responsive.css",
"~/Content/bootstrap-modal.css"
));
}
在我的视图中,如果不引用jquery,则无法执行此操作:
@{
ViewBag.Title = "Index";
}
<script>
$(document).ready(function () {
$("#btn1").click(function () {
alert("Text: " + $("#test").text());
});
$("#btn2").click(function () {
alert("HTML: " + $("#test").html());
});
});
</script>
<p id="test">This is some <b>bold</b> text in a paragraph.</p>
<button id="btn1">Show Text</button>
<button id="btn2">Show HTML</button>
@{
ViewBag.Title=“Index”;
}
$(文档).ready(函数(){
$(“#btn1”)。单击(函数(){
警报(“文本:+$(“#测试”).Text();
});
$(“#btn2”)。单击(函数(){
警报(“HTML:+$(“#test”).HTML());
});
});
这是段落中的粗体文本
显示文本
显示HTML
这项工作具有附加参考:
@{
ViewBag.Title = "Index";
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
$(document).ready(function () {
$("#btn1").click(function () {
alert("Text: " + $("#test").text());
});
$("#btn2").click(function () {
alert("HTML: " + $("#test").html());
});
});
</script>
<p id="test">This is some <b>bold</b> text in a paragraph.</p>
<button id="btn1">Show Text</button>
<button id="btn2">Show HTML</button>
@{
ViewBag.Title=“Index”;
}
$(文档).ready(函数(){
$(“#btn1”)。单击(函数(){
警报(“文本:+$(“#测试”).Text();
});
$(“#btn2”)。单击(函数(){
警报(“HTML:+$(“#test”).HTML());
});
});
这是段落中的粗体文本
显示文本
显示HTML
您的布局是什么样的?如何在视图中使用脚本?您是否将脚本放在脚本部分?我的水晶球今天早上不工作,我们需要查看一些代码:捆绑(在BundleConfig中)、您如何引用捆绑以及您试图对jQuery执行什么操作。我的水晶球告诉我,在定义jQuery之前,您正在尝试使用jQuery。读取生成的源。是否在布局中引用了正确的包?根据您的包配置,我认为应该是@Scripts.Render(“~/bundles/Bootstrap”)@Scripts.Render(“~/Scripts/Bootstrap”)正在被渲染。它们都在脚本文件夹中