DataTables警告:table id = {id} - Ajax错误

时间:2017-04-12 05:58:58

标签: c# json asp.net-mvc datatable

我正在尝试使用datatable将json绑定到表 这是我的代码Html

<table class="table table-bordered table-striped" id="dataTables-1">
                                <thead>
                                    <tr>
                                        <th>Customer Site Id</th>
                                        <th>Customer Product name</th>
                                        <th>Start Date Time</th>
                                        <th>Stop Date Time</th>
                                        <th>Upload</th>
                                        <th>Download</th>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>

这里是数据表的脚本

<script type="text/javascript">

            $("#btnFilter").click(function () {
                //var tab = $("#Tab").val().length;
                //var fromDate = $("#FromModel").val();
                //var toDate = $("#ToDate").val();

                CreateTableUsage();

            });

            function CreateTableUsage() {
                $('#dataTables-1').DataTable({
                    searching: false,
                    'bAutoWidth': false,
                    sAjaxSource: '@Url.Action("Filter") + ?tab=' + encodeURI($('#Tab').val()) + encodeURI($('#FromModel').val()) + encodeURI($('#ToDate').val()),
                    aoColumns: [
            { "sName": "SiteRefId", "bSortable": false },
            { "sName": "CustomerServiceRefId", "bSortable": false },
            { "sName": "StartTimeUtc", "bSortable": false },
            { "sName": "StopTimeUtc", "bSortable": false },
            { "sName": "CallingStationId", "bSortable": false },
            { "sName": "IpAddress", "bSortable": false }]
                });
            }
        </script>

这里是代码BackEnd

public ActionResult Filter(string tab, string FromDate, string ToDate)
{
   return Json(new { aaData = lUsage.Select( x => new object[] { x.SiteRefId, x.CustomerServiceRefId, x.StartTimeUtc , x.StopTimeUtc, x.CallingStationId, x.IpAddress}).ToList() }, JsonRequestBehavior.AllowGet);
}

当action返回json进行查看时,会引发datatable的错误 DataTables警告:表id = {id} - Ajax错误

0 个答案:

没有答案