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

‘Sorts’ parameter is null in MVC action

4 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 25 Mar 2013, 07:40 AM
Hi,

DataSourceRequest ‘Sorts’ parameter (‘Filters’ and ‘Groups’
too) are null in my MVC action. Other parameters (‘PageSize’, for example) bind
properly.

If I use MVC wrapper for Kendo Grid everything works
perfectly, but I need to connect grid’s data source with MVC action without
wrapper. Is it possible?

JS libraries bundle:
jquery.min.js
kendo.all.min.js
kendo.aspnetmvc.min.js

Grid example:
$('#cars').kendoGrid({
            pageable: true,
            sortable: true,
            dataSource: new kendo.data.DataSource({
                serverPaging: true,
                serverSorting: true,
                schema: { data: "Data", total: "Total" },
                transport: {
                    read: {
                        url: '@Url.Action("GetCars")',
                        contentType: "application/json; charset=utf-8",
                        type: "POST"
                    },
                    parameterMap: function (options) {
                        return JSON.stringify({ request: options }); 
                    }
                }
            })
        });

HTTP request:
{"request":{"sort":[{"field":"Name","dir":"desc"}]}}

MVC action:
[HttpPost]
public JsonResult GetCars([DataSourceRequest]DataSourceRequest request)
{
     ..............
}

 Thanks!

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 26 Mar 2013, 11:11 AM
Hello Max,

May I suggest you to use Kendo UI Grid MVC wrapper instead? It hides a bunch of logic required to send the content in proper format to the server in order to be properly parsed by MVC framework. Using Kendo UI MVC wrappers will do the proper DataSource setup for you.

Otherwise the data source configuration should looks similar to this:
dataSource: {
 type: "aspnetmvc-ajax"//<- !Important predefined settings included in kendo.aspnetmvc.min.js
 transport: {
  prefix: "",
  // other transport settings
 },
 schema: {
  data: "Data",
  total: "Total",
  errors: "Errors"
},
//etc.


You will also have to remove your implementation for parameterMap as `type: "aspnetmvc-ajax"` will provide you with default one which will format the data in a way that ASP.NET MVC ModelBinder understands.
Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Max
Top achievements
Rank 1
answered on 27 Mar 2013, 10:47 AM
Many thanks, Nikolay.
This clears up a lot for me.
I'll follow your suggestion to use MVC wrapper for grids.
One mode counter question: is it possible to connect grid's data source (declared with MVC wrapper) and asmx web service with input parameter of  'DataSourceRequest' type.

Thanks!
0
Nikolay Rusev
Telerik team
answered on 28 Mar 2013, 08:55 AM
Hello Max, 

I am afraid that you cannot bind MVC wrappers to web service. This will require changes in the Content-Type of the request(which is different for MVC framework) and many other settings which are not configurable via MVC wrappers.

However you can take a look at our Code Library projects. There is a runnable sample showing CRUD Grid operations with web service.

All the best,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Max
Top achievements
Rank 1
answered on 28 Mar 2013, 09:58 AM
Thanks for explanation!
Tags
Grid
Asked by
Max
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Max
Top achievements
Rank 1
Share this question
or