【问题标题】:DataTables warning - Incorrect column countDataTables 警告 - 列数不正确
【发布时间】:2022-11-17 22:32:58
【问题描述】:

我在 asp.net mvc 中编码,我正在尝试实现 DataTables.net 的表,但出现此错误: DataTables warning: table id=abc - Incorrect column count. For more information about this error, please see http://datatables.net/tn/18

这是我的桌子:

<table id="abc" class="display table-bordered table-hover">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.StudentID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FirstName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.LastName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Program)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.YearGraduate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.BoardScore)
        </th>
        <th>Action</th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.StudentID)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FirstName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LastName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Program)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.YearGraduate)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.BoardScore)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.StudentID }, new { @class = "btn btn-primary" }) &nbsp;&nbsp;&nbsp;
                @Html.ActionLink("Details", "Details", new { id = item.StudentID }, new { @class = "btn btn-success" })&nbsp;&nbsp;&nbsp;
                @Html.ActionLink("Delete", "Delete", new { id = item.StudentID }, new { @class = "btn btn-danger" })
            </td>
        </tr>
    }

</table>

【问题讨论】:

  • 您在 javascript 中的数据表初始化是什么样的,您似乎也错过了 <thead> 和 <tbody>

标签: javascript c# html html-table datatable


【解决方案1】:

您的表格不正确,您缺少 <thead> 和 <tbody> 标记。

这是一个有效的表:

<table>
    <thead>
        <tr>
            <th>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
            </td>
        </tr>
    </tbody>
</table>

【讨论】:

    猜你喜欢
    • 2014-06-15
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多