简体   繁体   English

jQuery的数据表未初始化

[英]JQuery's Datatable doesn't get initialized

I'm currently building a MVC application with C#. 我目前正在使用C#构建MVC应用程序。 I've used a Datatable in my user overview before, but when I want to use it in the detail page, in a partial view, it often doesn't load. 之前,我曾在用户概述中使用过数据表,但是当我想在详细信息页面中以局部视图使用它时,通常不会加载它。 Below I've copied the most important part of my DetailsGroup.cshtml file. 下面,我复制了DetailsGroup.cshtml文件中最重要的部分。 While coding, I've basically copy/pasted from my working Overview page, but somehow it doesn't work. 编码时,我基本上是从工作中的“概述”页面复制/粘贴的,但是以某种方式不起作用。

@{
Layout = "~/Views/Shared/_LayoutWithoutNavBar.cshtml";
}

<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.css" />
<html> 
....
<table id="myGroups">
....
</html>

@section scripts {
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.5/js/jquery.dataTables.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        //onderstaand lijntje is om een deftige dataTable te initialiseren
        $('#myGroups').DataTable({
            "searching": false,
            "pageLength": 25
        });
    });

</script>
}

In my _LayoutWithoutNavBar.cshtml file I have the following bits of code: 在我的_LayoutWithoutNavBarBar.cshtml文件中,我具有以下代码位:

<head>
    ...
    @Styles.Render("~/Content/bootstrap-theme.min.css")
    @Styles.Render("~/Content/bootstrap.min.css")
    @Scripts.Render("~/bundles/modernizr")


</head>
<body role="document">
    <div id="mainBody" class="giveMeSomeSpace">
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/bundles/jqueryui")
        @Scripts.Render("~/bundles/jqueryval")

        @RenderSection("scripts", required: false)

        @Styles.Render("~/Content/themes/base/css")
        @RenderBody()


    </div>
</body>
</html>

In my main _Layout.cshtml file, which is also used in the Details page, I use the same scripts, described above. 在我的主要_Layout.cshtml文件中(也在“详细信息”页面中使用过),我使用与上述相同的脚本。 I don't know if a partial view can use those though, so I kinda copy/pasted to be sure. 我不知道部分视图是否可以使用那些视图,所以我肯定会复制/粘贴。

EDIT: almost forgot. 编辑:几乎忘了。 When I run the app, I don't get an error, the table just gets sloppily loaded, no functionality or css. 当我运行该应用程序时,我没有收到错误,该表只是被缓慢加载,没有任何功能或CSS。 If I open F12 on Chrome, I see a red Uncaught TypeError: undefined is not a function If I click on that error, it sends me to the < head > tag of my main Details page 如果我在Chrome上打开F12, 则会看到红色的Uncaught TypeError:undefined不是一个函数如果单击该错误,它将发送到我的“详细信息”主页面的<head>标记

I've found the answer. 我找到了答案。 By using a mix of parents and partial views, I ended up using JQuery twice or even thrice. 通过混合使用父视图和局部视图,我最终两次使用JQuery,甚至三次。 So presss F12 to check if you don't do that. 因此,按F12键检查您是否不这样做。

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

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