Reputation: 7505
So I've been trying out the Kendo UI grid and I initially started with just the plain non-MVC helper generated client side grid, taking data from a Web API controller via GET. Worked just fine but was starting to get messy model binding the sort and filter parameters.
So I started using the MVC helpers and ran into a problem, which is this:
When using the non-MVC generated grid, configured to use GET and with the dataSource "type" NOT SET, the GET params look like this:
page 1
pageSize 10
skip 0
sort[0][dir] asc
sort[0][field] OrderID
take 10
This is the correct form to bind to the DataSourceRequest MVC helper...BUT if I render said grid using the MVC extension, it sets the dataSource "type" to "aspnetmvc-ajax" which causes the GET params to look like this:
filter
group
page 1
pageSize 10
sort OrderID-asc
(and if you have multiple sort params it joins them with a "~".). This second format will not bind properly to DataSourceRequest and so you end up with a null "Sorts" member....this seems completely backwards to me because you would only have the DataSourceRequest helper if you were using the MVC extension - but when you use them, the data is being sent incorrectly!
I also tried POSTing to a regular MVC Controller as per the examples and had the same problem.
In any case, I'm trying to find a way to tell the extension to not render the aspnetmvc-ajax. Anyone have any ideas? Thanks in advance...
Upvotes: 1
Views: 4388
Reputation: 7505
ok so the solution was to use the model binder provided for webapi found in the sample code here:
Kendo UI Grid Params model binder for Web API
which I found quite by accident....Of course, that's just the beginning of my "adventure" with Kendo UI....
Upvotes: 1
Reputation: 20223
The MVC Extensions are using the aspnet-ajax transport settings and they are bound to the DataSourceRequest object if you use the DataSourceRequest attribute which will handle the binding. Check the controller code of the demos.
public ActionResult EditingCustom_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(SessionClientProductRepository.All().ToDataSourceResult(request));
}
Upvotes: 2