【问题标题】:DataTable is not showing only return json format?DataTable 不显示仅返回 json 格式?
【发布时间】:2021-01-23 06:56:01
【问题描述】:

我有一个逻辑,希望它显示 dataTable,目前它显示的是 json 格式,需要一些帮助来解决这个问题。我将在结果的屏幕截图下方附上,我想知道为什么它返回该格式而不是 DataTable 的原因?

//GET:Data-Using-DataTable.
        public ActionResult GeteNtsaDataResults()
        {
            using (eNtsaRegistration_2 model = new eNtsaRegistration_2())
            {
                List<eNtsaRegPeopleList> eNtsaRegs = cb.RegPeopleLists.ToList<eNtsaRegPeopleList>();
                return Json(new { data = eNtsaRegs }, JsonRequestBehavior.AllowGet);
            }
        }

@{
    ViewBag.Title = "People_Lists";
}

<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/jquery.dataTables.min.js"></script>
<script src="~/Scripts/dataTables.bootstrap4.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {    
        $('#dataTable').DataTable({    
            "ajax": {    
                "url": "/Home/GeteNtsaDataResults",    
                "type": "GET",    
                "datatype": "json"  ,  
                 "dataSrc": ""  
  
            },    
            "columns": [    
                { "data": "LoginID" },    
                { "data": "Name" },    
                { "data": "SSID" },    
                { "data": "Section" },    
                { "data": "Role" },    
                { "data": "LastActivity" },    
                { "data": "TotalActivity" }    
            ]    
        });    
    }); 

</script>

<div class="container py-4">
    <h4 class="text-center text-uppercase"></h4>
    <div id="dataTable_wrapper"></div>
    <table id="dataTable" class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>LoginID</th>
                <th>Name</th>
                <th>SSID</th>
                <th>Section</th>
                <th>Role</th>
                <th>LastActivity</th>
                <th>TotalActivity</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>

【问题讨论】:

  • @Sujit 谢谢让我在这个例子上工作,我可能会错过一些东西。如果我坚持这些变化,我会大喊大叫。

标签: c# jquery asp.net-mvc bootstrap-4 datatable


【解决方案1】:

参考这个例子。 -> https://datatables.net/examples/basic_init/data_rendering.html

从 HTML 中删除“tbody”标签。还要为数据表添加相关的css。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 2018-01-21
    • 2014-02-12
    • 2017-03-26
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    相关资源
    最近更新 更多