Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 无法读取属性';长度';使用Ajax数据表定义未定义的_Jquery_Ajax_Asp.net Mvc_Datatables - Fatal编程技术网

Jquery 无法读取属性';长度';使用Ajax数据表定义未定义的

Jquery 无法读取属性';长度';使用Ajax数据表定义未定义的,jquery,ajax,asp.net-mvc,datatables,Jquery,Ajax,Asp.net Mvc,Datatables,在ajax调用返回后,我当前在浏览器中遇到以下错误: Cannot read property 'length' of undefined 这是我的html: <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable"> <colgroup> <col class="con0" /> <col class="con1" />

在ajax调用返回后,我当前在浏览器中遇到以下错误:

Cannot read property 'length' of undefined
这是我的html:

<table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
<colgroup>
    <col class="con0" />
    <col class="con1" />
    <col class="con0" />
    <col class="con1" />
</colgroup>
<thead>
    <tr>
        <th>Id</th>
        <th>SerialNumber</th>
        <th>AccountCode</th>
        <th>ClientId</th>         
    </tr>
</thead>   
<tbody>       
</tbody>
</table>

身份证件
序列号
会计代码
客户
以下是JS:

  <script type="text/javascript">
    $(document).ready(function () {
        $('#dyntable').dataTable({
            stateSave: true,
            serverSide: true,
            searchDelay: 300,
            autoWidth: false,
            ajax: {
                url: 'Search',
                type: 'POST',                    
            },
            order: [[0, "asc"]],
            processing: true,
            columns: [
                {
                    "sName": "Id",
                    "bSortable": false
                },
                {
                    "sName": "SerialNumber",
                    "bSortable": true
                },
                {
                    "sName": "AccountCode",
                    "bSortable": true
                },
                {
                    "sName": "ClientId",
                    "bSortable": true
                }
            ]
        });
        // DataTables Length to Select2
        jQuery('div.dataTables_length select').removeClass('form-control input-sm');
        jQuery('div.dataTables_length select').css({ width: '60px' });
        jQuery('div.dataTables_length select').select2({ minimumResultsForSearch: -1 });
    });
</script>

$(文档).ready(函数(){
$('#dyntable')。数据表({
stateSave:没错,
服务器端:是的,
搜索延迟:300,
自动宽度:false,
阿贾克斯:{
url:'搜索',
键入:“POST”,
},
订单:[[0,“asc”]],
处理:对,
栏目:[
{
“sName”:“Id”,
“可移植”:false
},
{
“sName”:“序列号”,
“可移植”:真
},
{
“sName”:“账户代码”,
“可移植”:真
},
{
“sName”:“ClientId”,
“可移植”:真
}
]
});
//要选择的数据表长度2
jQuery('div.dataTables_length select').removeClass('form-control input sm');
jQuery('div.dataTables_length select').css({width:'60px'});
jQuery('div.dataTables_length select').select2({minimumResultsForSearch:-1});
});
最后是我的行动方法:

     [HttpPost]
    public async Task<ActionResult> Search(FilterRequest filter)
    {
        try
        {
            IQueryable<SerialRouting> filteredItems = db.SerialRoutings;
            if (!string.IsNullOrEmpty(filter.Search.Value))
            {
                filteredItems = db.SerialRoutings.Where(c =>
                c.AccountCode.Contains(filter.Search.Value)
                || c.Client.ClientID.Contains(filter.Search.Value)
                || c.Serialnumber.ToString().Contains(filter.Search.Value)
               );
            }
            int totalRecords = filteredItems.Count();
            filteredItems = filteredItems.OrderBy(x => x.Serialnumber);
            filteredItems = filteredItems.Skip(filter.Start).Take(filter.Length);
            var displayItems = await filteredItems.Select(x => new SerialRoutingViewModel { Id = x.SerialRoutingIdentity, SerialNumber = x.Serialnumber, AccountCode = x.AccountCode, ClientId = x.Client.ClientID }).ToListAsync();
            return Json(new PageResponse<SerialRoutingViewModel>(filter.Draw, totalRecords, displayItems.Count, displayItems.ToArray()));
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        return null;
    }
[HttpPost]
公共异步任务

我使用的是数据表V1.10.10


我遗漏了什么?

JSON是什么样子的?甚至调用了控制器操作吗?通常,ajax调用中的url需要rootulr+/Controller/Actionyes,当我调试控制器操作并成功返回数据时。
sName
是v1.9语法,但不确定这是否是问题的原因。JSON看起来如何?控制器操作是否被调用?通常,ajax调用中的url需要rootulr+/Controller/Actionyes,当我调试调用的控制器操作并成功返回数据时。
sName
是v1.9语法-但不确定这是否是问题的原因。