Reputation: 576
I'm trying to implement server-side paging and sorting for jquery-datatable. but the issue is I'm not able to bind data posted by datatable to my action model to do sort and filter
Here is the data posted by jquery-datatable ajax request
draw:5
columns[0][data]:FirstName
columns[0][name]:FirstName
columns[0][searchable]:true
columns[0][orderable]:true
columns[0][search][value]:
columns[0][search][regex]:false
columns[1][data]:LastName
columns[1][name]:LastName
columns[1][searchable]:true
columns[1][orderable]:true
columns[1][search][value]:
columns[1][search][regex]:false
......
columns[n][data]:Position
columns[n][name]:Position
columns[n][searchable]:true
columns[n][orderable]:true
columns[n][search][value]:
columns[n][search][regex]:false
order[0][column]:1
order[0][dir]:desc
start:0
length:10
search[value]:
search[regex]:false
and my action method is:
public JsonResult GetGridData(GridFilter filter)
{ ....}
and my model classes are
public class GridFilter
{
public int draw { get; set; }
public List<ColModel> columns { get; set; }
public List<Order> order { get; set; }
public int start {get;set;}
public int length {get;set;}
public search search { get; set; }
}
public class ColModel
{
public string data { get; set; }
public string name { get; set; }
public string searchable { get; set; }
public string orderable { get; set; }
}
public class Order
{
public string dir { get; set; }
public string column { get; set; }
}
public class search
{
public string value {get;set;}
public string regex {get;set;}
}
How can I make data bind properly using default mvc model binders are a custom one.
Thanks
Upvotes: 0
Views: 1141
Reputation: 4014
Make sure your model properties have the same data types as defined here.
Also you have gone one level too far with your models.They are sent as individual parameters so you don't need the GridFilter
model, they should be received like so:
[HttpPost]
public JsonResult GetGridData(List<ColModel> columns, List<Order> order, Search search, int? start, int? length, int? draw)
{
}
Upvotes: 1