3

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

4
  • Are you sure you're expecting the correct structure of request parameters, especially search[value]? Commented May 13, 2015 at 14:01
  • I'm not expecting anything, the Nuget package and the jquery library work together with no custom code needed. Commented May 13, 2015 at 14:05
  • If you're using server-side processing, you need to add 'serverSide': true DataTables parameter. Commented May 13, 2015 at 14:19
  • @Gyrocode.com Server side was what I needed to use, not the ajax example found on the site. If you want to make it an answer I'll accept it. Commented May 13, 2015 at 17:23

1 Answer 1

3

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)'
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.