This is a migrated thread and some comments may be shown as answers.

How do I use the DataSourceRequest object as an asp.net mvc action parameter?

8 Answers 1529 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 06 Oct 2015, 10:11 PM

Is it possible to use the DataSourceRequest object as an action method parameter? What I've got currently is a grid that loads data, but then won't filter or sort. The paging seems to work.

I'm using Kendo UI verison 2015.3.930.

Thanks!

8 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 06 Oct 2015, 10:24 PM
Some additional information. I have been using this as an example: http://blog.falafel.com/server-paging-sorting-filtering-kendo-datasourcerequest/
0
Rosen
Telerik team
answered on 08 Oct 2015, 01:31 PM

Hello Aaron,

Could you please verify that you have correctly included kendo.aspnetmvc.min.js file.

If you continue to experience difficulties please provide a detail information about the implementation you are using, such as Grid and DataSource declaration as well as server-side action method. 

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Aaron
Top achievements
Rank 1
answered on 09 Oct 2015, 06:02 PM

Yes, I have included kendo.aspnetmvc.min.js.

One strange thing that's happening is that when I add type: 'aspnetmvc-ajax' into the DataSource configuration the data source doesn't load any data and just doesn't work. If I take it out, then the grid loads data and acts normally, but the filter post to the server never fires.

This give you some more information about the issue I'm trying to solve. The following post I think explains the problem. In my case the problem is happening when trying to filter a grid column on a date value. We're using the date picker on the column to select a date to filter on, but I believe the timezone is different and so the filter doesn't work.

 http://www.telerik.com/forums/kendo-grid-automatically-converting-timezone#kOFCrmYG0Em8FKn1B-EV9Q

Example:

 On the column header I select 11/7/2015 to filter on. I can see that the value of "2015-11-07T07:00:00.000Z" is being passed in the request to the server in the grid filter.

The request on the server side is then showing that the server is receiving the value as "11/06/2015 23:00:00". I'm assuming this change in date value for the filter is happening because of a timezone difference.

So I wanted to try and solve the problem using the following code.

http://www.crowbarsolutions.com/ignoring-time-when-filtering-dates-in-telerik-kendo-grids/​

 

0
Aaron
Top achievements
Rank 1
answered on 09 Oct 2015, 06:17 PM
I forgot to add that when the configuration does not use type: 'aspnetmvc-ajax' the grid loads data using the DataSourceRequest class as a action method parameter but the filter values are always null.
0
Rosen
Telerik team
answered on 12 Oct 2015, 12:56 PM

Hello Aaron,

Using the DataSourceRequest/DataSourceResult classes from Kendo.MVC assembly requires use of the aspnetmvc-ajax transport type on the client-side. This is needed as the transport uses specific parameterMap which format the request parameters for sorting, filtering, etc. in the appropriate way in which the DataSourceRequest ModelBinder will be able to populate the DataSourceRequest instance. The paging information will be OK without the aspnetmvc-ajax transport as page and pageSize are primitive values and will be bound directly.

Thus, in order to be able to tell what is causing filter and sort to not be populated, I would ask you to provide a small runnable sample in which the issue can be observed locally.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Aaron
Top achievements
Rank 1
answered on 23 Oct 2015, 07:47 PM

I've done some more testing and have found that I'm getting an exception when the grid first tries to load data. This is when I set the option type: 'aspnetmvc-ajax'.

System.ArgumentException: Invalid JSON primitive: sort.

var dataSource = new kendo.data.DataSource({
            pageSize: 50,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true,
            batch: true,
            type: 'aspnetmvc-ajax',
            transport: {
                read: {
                    url: controller + "/read",
                    contentType: "application/json; charset=utf-8",
                    type: "POST"
                },

 

[HttpPost]
[Route("read")]
public ActionResult Read([DataSourceRequest] Kendo.Mvc.UI.DataSourceRequest request)
{
    var results = context.boks_recon_report.AsQueryable().OrderBy(e => e.ServerName).ToDataSourceResult(request);
    return Json(results);
}

0
Rosen
Telerik team
answered on 26 Oct 2015, 12:16 PM

Hello Aaron,

I suspect that the error is most probably cause by incorrect content type. You should remove the content type setting from read settings:

read: {
    url: controller + "/read",
  //  contentType: "application/json; charset=utf-8",
    type: "POST"
}

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Aaron
Top achievements
Rank 1
answered on 30 Oct 2015, 06:50 PM
Thank you, that worked!
Tags
Grid
Asked by
Aaron
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or