‘Sorts’ parameter is null in MVC action

5 posts, 1 answers
  1. Answer
    Max
    Max avatar
    5 posts
    Member since:
    Mar 2013

    Posted 25 Mar 2013 Link to this post

    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!
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 26 Mar 2013 Link to this post

    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!
  3. Max
    Max avatar
    5 posts
    Member since:
    Mar 2013

    Posted 27 Mar 2013 Link to this post

    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!
  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 28 Mar 2013 Link to this post

    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!
  5. Max
    Max avatar
    5 posts
    Member since:
    Mar 2013

    Posted 28 Mar 2013 Link to this post

    Thanks for explanation!
Back to Top