I've followed the example shown on the datatables website for making an ajax request and I can't get it to work with the data tables nuget package. The model binder is mad because the search value is null and expects it to be an empty string.
我按照datatables网站上显示的例子来制作一个ajax请求,我无法使用数据表nuget包。模型绑定器很疯狂,因为搜索值为null并且期望它是一个空字符串。
Controller:
public JsonResult ListUsers([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest request)
View:
<table id="users-table" class="table table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
</table>
$(function() {
$('#users-table').dataTable({
ajax: '@Url.Action("ListUsers", "Businesses",null,Request.Url.Scheme)'
});
});
The value of the search cannot be null. If there's no search performed, provide an empty string. Parameter name: value
搜索的值不能为null。如果没有执行搜索,请提供空字符串。参数名称:value
1 个解决方案
#1
If you're using server-side processing, you need to add 'serverSide': true
as DataTables parameter, see the code below:
如果您正在使用服务器端处理,则需要添加'serverSide':true作为DataTables参数,请参阅以下代码:
$('#users-table').dataTable({
'serverSide': true,
'ajax': '@Url.Action("ListUsers", "Businesses",null,Request.Url.Scheme)'
});
#1
If you're using server-side processing, you need to add 'serverSide': true
as DataTables parameter, see the code below:
如果您正在使用服务器端处理,则需要添加'serverSide':true作为DataTables参数,请参阅以下代码:
$('#users-table').dataTable({
'serverSide': true,
'ajax': '@Url.Action("ListUsers", "Businesses",null,Request.Url.Scheme)'
});