Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with jquery datatables ajax datasource

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.

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

like image 383
The Muffin Man Avatar asked Apr 01 '26 19:04

The Muffin Man


1 Answers

If you're using server-side processing, you need to add 'serverSide': true as DataTables parameter, see the code below:

$('#users-table').dataTable({
  'serverSide': true,
  'ajax': '@Url.Action("ListUsers", "Businesses",null,Request.Url.Scheme)'
});
like image 98
Gyrocode.com Avatar answered Apr 03 '26 17:04

Gyrocode.com



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!