Proper bundling of DataTables in ASP.net MVC

一笑奈何 提交于 2019-12-11 08:49:59

问题


I've run nuget for datatables and I'm trying to bundle them so that it works in all my views. However, it doesn't seem to be working properly. the datatable functionality is occuring, but the Datatables formatting is not occuring. I assume I'm not bundling the CSS properly, but I'm not sure. Here is my bundle in BundleConfig:

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

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

and then _Layout:

    @Scripts.Render("~/bundles/datatables")
    @Styles.Render("~/content/datatables")

and here is the view I'm attempting to us it in:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script >
$(document).ready(function () {
    var table = $('#SchedulesTable').DataTable();
});
</script>

What am I doing wrong?


回答1:


I don't believe that you can use "~/Content/datatables" as a CSS bundle when that directory actually exists. It looks like it already exists since what you are trying to include is: "~/Content/DataTables/css/dataTables.bootstrap.css". The content/datatables is a real existing directory. Name the bundle something else, you should be fine.




回答2:


OK, it was a combination of two things. the first was I did not included a css file in the bundle that I should have (the file jquery.dataTables.css), AND on top of that I was using a directory that actually existed. Adding the additional file to the bundle and changing to a director that doesn't exist fixed it.



来源:https://stackoverflow.com/questions/50748509/proper-bundling-of-datatables-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!