2015-05-12 137 views
3

我已经按照datatables网站上显示的示例进行ajax请求,我无法让它与数据表nuget包一起工作。模型联编程序是疯狂的,因为搜索值为空,并期望它是一个空字符串。jquery datatables问题ajax datasource

控制器:

public JsonResult ListUsers([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest request) 

查看:

<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)' 
    }); 
}); 

搜索的值不能为空。如果没有执行搜索,请提供一个空字符串。 参数名:价值

+0

你确定你期待的[正确的结构请求参数](http://datatables.net/manual/server-side#Sent-parameters),尤其是'search [value]'? –

+0

我不期待任何事情,Nuget包和jquery库一起工作,不需要自定义代码。 –

+0

如果您使用服务器端处理,则需要添加''serverSide':true' DataTables参数。 –

回答

3

如果您正在使用服务器端的处理,则需要添加'serverSide': true的数据表的参数,请参见下面的代码:

$('#users-table').dataTable({ 
    'serverSide': true, 
    'ajax': '@Url.Action("ListUsers", "Businesses",null,Request.Url.Scheme)' 
});