2015-05-12 48 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)' 
});