我在_Layout.cshtml中编写了这样的代码:
<head>
<link href="@Url.Content("~/Content/jquery.fancybox-1.3.4.css")" rel="stylesheet" type="text/css" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.easing.1.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.fancybox-1.3.4.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//alert("H");
$('#gallery a').fancybox({
});
}); // end ready
</script>
</head>
<body>
<div id="gallery" >
<a href="../../Content/Images/Slide1.JPG" rel="gallery" title="Img1!:)">
<img alt="Dog" height="170" src="../../Content/Images/Slide1_s.JPG" width="200" /></a>
<a href="../../Content/Images/Slide2.JPG" rel="gallery" title="Img2!:)">
<img alt="Cat" height="170" src="../../Content/Images/Slide2_s.JPG" width="200" /></a>
</div>
</body>
我在简单的html文件中使用了上面的代码,它运行得很好。但是,如果我尝试将此代码放在MVC 4中,它就不起作用。只是图像的链接工作,它只显示没有“新弹出窗口”的图像。我检查了很多次“.js”库的所有地址,并推出了“alert('Hello from .js')”来检查这些库的“Scripts”文件夹的可用性。
这是什么原因?怎么解决?
答案 0 :(得分:0)
我刚刚移动了“@ Scripts.Render(”〜/ bundles / jquery“)”和“@RenderSection(”scripts“,required:false)”来自它,它完美无缺!
整个代码是:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta charset="utf-8" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
<link href="~/Icon.ico" rel="shortcut icon" type="image/x-icon" />
</head>