我创建了一个js文件包(“ bundles / js”),其中包含了页面所需的所有js文件。
@Scripts.Render("/bundles/js")
渲染后,它在上面的行中引发错误:
无法加载资源:服务器的响应状态为404(未找到)
,渲染后看起来像
<script scr="/bundles/js">
但是页面上没有任何内容。
我已经注释了对所有js文件的引用,并放置了渲染器,但是它不起作用。
我在项目中的web.config中包含了优化dll,还添加了bundlesConfig类
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/js").Include("~/Content/js/jquery.min.js",
"~/Content/js/bootstrap.min.js",
"~/Content/js/owl.carousel.js",
"~/Content/js/jquery.ajaxchimp.js",
"~/Content/js/smooth-scroll.js",
"~/Content/js/jquery.magnific-popup.min.js",
"~/Content/js/waypoints.min.js",
"~/Content/js/jquery.counterup.js",
"~/Content/js/menumaker.js",
"~/Content/js/jquery.appear.js",
"~/Content/js/jquery.countdown.js",
"~/Content/js/price-slider.js",
"~/Content/js/bootstrap-datepicker.js",
"~/Content/js/jquery.elevatezoom.js",
"~/Content/js/theme.js",
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.min.js",
"~/Scripts/DataTables/jquery.dataTables.min.js",
"~/Content/sweetalert/sweetalert.min.js",
"~/Scripts/DataTables/dataTables.buttons.min.js",
"~/Scripts/DataTables/buttons.flash.min.js",
"~/Scripts/DataTables/pdfmake.min.js",
"~/Scripts/DataTables/vfs_fonts.js",
"~/Scripts/DataTables/buttons.html5.min.js",
"~/Scripts/DataTables/buttons.print.min.js",
"~/Content/js/blockUI.js"));
}
}
然后在application_start中注册
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
先前的文件顺序为:
<script src="~/Content/js/bootstrap.min.js"></script>
<script src="~/Content/js/owl.carousel.js"></script>
<script src="~/Content/js/jquery.ajaxchimp.js"></script>
<script src="~/Content/js/smooth-scroll.js"></script>
<script src="~/Content/js/jquery.magnific-popup.min.js"></script>
<script src="~/Content/js/waypoints.min.js"></script>
<script src="~/Content/js/jquery.counterup.js"></script>
<script src="~/Content/js/menumaker.js"></script>
<script src="~/Content/js/jquery.appear.js"></script>
<script src="~/Content/js/jquery.countdown.js"></script>
<script src="~/Content/js/price-slider.js"></script>
<script src="~/Content/js/bootstrap-datepicker.js"></script>
<script src="~/Content/js/jquery.elevatezoom.js"></script>
<script src="~/Content/js/theme.js"></script>
<script src='@Url.Content("~/Scripts/jquery.validate.min.js")' type='text/javascript'></script>
<script src='@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")' type='text/javascript'></script>
<script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
<script src="~/Content/sweetalert/sweetalert.min.js"></script>
<script src="~/Scripts/DataTables/dataTables.buttons.min.js"></script>
<script src="~/Scripts/DataTables/buttons.flash.min.js"></script>
<script src="~/Scripts/DataTables/pdfmake.min.js"></script>
<script src="~/Scripts/DataTables/vfs_fonts.js"></script>
<script src="~/Scripts/DataTables/buttons.html5.min.js"></script>
<script src="~/Scripts/DataTables/buttons.print.min.js"></script>
<script src="~/Content/js/blockUI.js"></script>
答案 0 :(得分:0)
您在@Scripts.Render("/bundles/js")
中缺少波浪号
尝试-@Scripts.Render("~/bundles/js")
答案 1 :(得分:0)
//Add into web config
<system.web>
<compilation debug="false" />
</system.web>
public static void RegisterBundles(BundleCollection bundles)
{
//Enable bundling
BundleTable.EnableOptimizations = true;
}