Mvc4数据表在脚本包中不起作用 [英] Mvc4 datatables does not work in script bundle
本文介绍了Mvc4数据表在脚本包中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 App_Start / BundleConfig.cs 中有以下代码:
I have following code in the App_Start/BundleConfig.cs
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/datatable").Include(
"~/Content/DataTables-1.10.7/media/js/jquery.dataTables.min.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/site.css",
"~/Content/DataTables-1.10.7/media/css/jquery.dataTables.min.css"));
以及 Views / Shared / _Layout.cshtml
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/datatable")
和CSS和Datatable不能正常工作,但是当我手动添加时
and CSS and Datatable just does not work, but when I add manualy
<link href='@Url.Content("~/Content/DataTables-1.10.7/media/css/jquery.dataTables.min.css")' rel="stylesheet" />
<script src='@Url.Content("~/Content/DataTables-1.10.7/media/js/jquery.dataTables.min.js")' type="text/javascript"></script>
它开始工作。我在做什么错了?
it starts to work. What am I doing wrong ?
推荐答案
从浏览器检查网页的源代码,并确保;
Inspect the source code of the web page from the browser and be sure that;
jquery.dataTables.min.js 正在加载之后 jquery.min.js
将 _Layout.cshtml 中的顺序更改为:
@Scripts.Render("~/bundles/jquery")
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/datatable")
编辑:
它也可能与 web.config 设置有关。
如果您的web.config文件中包含 Debug = True ,则捆绑包中将不包含最小化的javascript文件。
If you have "Debug = True" in your web.config, minimized javascript files are not include in bundles.
添加此内容到您的 BundleConfig.cs :
#if DEBUG
//by default all minimized files are ignored in DEBUG mode. This will stop that.
bundles.IgnoreList.Clear();
#endif
这篇关于Mvc4数据表在脚本包中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文