【问题标题】:TBody not working on table with Jquery DataTableTBody 无法使用 Jquery DataTable 处理表
【发布时间】:2018-08-28 09:28:12
【问题描述】:

我在我的项目中使用 JQuery 数据表。

我有 ActionResult 并正在获取数据。我想在表格中显示数据,但如果我使用 tbody,数据表格的样式看起来不像普通表格。

我尝试不使用数据并编写自定义 tbody 和 tr 标签。我的问题是继续。我哪里错了?

操作结果

 public ActionResult YayinEvleri()
        {
            dbContext = new DatabaseContext();
            var yayinEvleri = dbContext.YayinEvi.ToList();

            return View(yayinEvleri);
        }

查看

@model List<KitapFuari.Models.Yayinevi>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js "></script>

<script>
    $(document).ready( function () {
    $('#yayinEvleri').DataTable();
    });
    </script>
 <table id="yayinEvleri" class="table table-striped table-bordered" style="width:100%" cellspacing="0">
            <thead>
                <tr>
                    <th>Yayın Evi</th>
                    <th>Yazar</th>
                </tr>
            </thead>
            <tbody>
              @foreach (var item in Model)
                {
                    <tr>
                        <td>@item.Ad</td>
                    </tr>

                }
            </tbody>

        </table>

【问题讨论】:

  • 请阅读 datatables.net 在您的代码中使用数据表
  • 我看过这个页面。我以前用过数据表。

标签: asp.net-mvc datatables


【解决方案1】:

添加此脚本。

$(document).ready( function () {
$('#yayinEvleri').DataTable();
});

【讨论】:

  • 我已经有了。请仔细阅读我的帖子。我的问题不在于第一次加载。当我使用 tbody 时,数据表样式丢失。
  • 你需要两个 td 标签,因为你有两个。
  • 我尝试了 2 个 td 标签。同样的问题。对不起我的英语:)
猜你喜欢
  • 2011-07-28
  • 2018-10-07
  • 1970-01-01
  • 2021-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多