简体   繁体   English

ASP.net MVC 中的数据表捆绑问题

[英]dataTables bundling issue in ASP.net MVC

I have a problem with bundling dataTables library.我在捆绑 dataTables 库时遇到问题。 This is what I've got now:这就是我现在所拥有的:

//other bundles (bootstrap etc.)

bundles.Add(new ScriptBundle("~/bundles/datatables").Include(
           "~/Scripts/jquery.dataTables.js"));

bundles.Add(new StyleBundle("~/Content/css").Include(
           "~/Content/bootstrap.css",
           "~/Content/site.css",
           "~/Content/DataTables/css/dataTables.bootstrap.css",
           "~/Content/DataTables/css/jquery.dataTables.css"));

and in _Layout.cshtml :_Layout.cshtml 中

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="~/Content/fontawesome-all.min.css" rel="stylesheet" />

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

<head>
...
</head>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/datatables")
@RenderSection("scripts", required: false)

Unfortunately it doesn't work, table is not modified.不幸的是它不起作用,表没有被修改。 Another issue is that when I press F12 to inspect my website I don't see Scripts/datatables attached on the end, only this:另一个问题是,当我按 F12 检查我的网站时,我没有看到最后附加的Scripts/datatables ,只有这个:

<script src="/Scripts/jquery-3.5.1.js"></script>
<script src="/Scripts/bootstrap.js"></script>

additionally I can see th error: Uncaught TypeError: $(...).DataTable is not a function at HTMLDocument....另外我可以看到错误: Uncaught TypeError: $(...).DataTable is not a function at HTMLDocument....

my JS looks like this:我的 JS 看起来像这样:

$('document').ready(function () {
    $('#myTable').DataTable({
        "order": [[3, "desc"]]
    });
});

Your /Scripts/jquery.dataTables.js file does not seem to be loading.您的/Scripts/jquery.dataTables.js文件似乎没有加载。 That is why you see the error on the console.这就是您在控制台上看到错误的原因。

Can you try to load the datatable library with <script src="/Scripts/jquery.dataTables.js"></script> referance instead of the existing @Scripts.Render("~/bundles/datatables") ?您可以尝试使用<script src="/Scripts/jquery.dataTables.js"></script>而不是现有的@Scripts.Render("~/bundles/datatables")加载数据表库吗?

Also you seem to be loading jquery library twice!?您似乎还两次加载 jquery 库!?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM