'Sort' parameter of DataSourceRequest in MVC action is null.

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

    Posted 22 Mar 2013 Link to this post

    Hi,

    I've got the next problem:  'Sorts' parameter of DataSourceRequest is null.
    I've found a few threads here with similar issues but the only difference is that i'm not using MVC wrapper for Kendo Grid. Also I can confirm that MVC wrapper works perfectly in my case, but I need to manage grid without it.

    Here is the simple sample of what i've got now. What I'm doing wrong?

    My scripts bundle:
    - jquery.min.js 
    - kendo.all.min.js 
    - kendo.aspnetmvc.min.js

    Kendo Grid declaration:
     $('#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 (data) {
                            return JSON.stringify({ request: data }); 
                        }
                    }
                })
            });

    Action:
    public DataSourceResult GetCars([DataSourceRequest]DataSourceRequest request)
    {
        ............................
    }

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

    Thanks!
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 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. UI for ASP.NET MVC is VS 2017 Ready
  4. Laurent
    Laurent avatar
    4 posts
    Member since:
    Aug 2015

    Posted 02 Oct Link to this post

    Hi There,

    I am using Angular, KendoGrid, with MVC5 but The Sort/Group/Filter is always null in controller regardeless of what i have tried. I read many thread and i believe i am doing what i should do but the value are null. Please let me know what the issue is.

     

    <script src="/Scripts/kendo/2016.3.914/jquery.min.js"></script>
    <script src="/Scripts/kendo/2016.3.914/angular.min.js"></script>
    <script src="/Scripts/kendo/2016.3.914/jszip.min.js"></script>
    <script src="/Scripts/kendo/2016.3.914/kendo.all.min.js"></script>
    <script src="/Scripts/kendo/2016.3.914/kendo.aspnetmvc.min.js"></script>

     

    <div id="example" ng-app="MyApp">
        <div ng-controller="supplierController" style="height:200px">
            <kendo-grid options="supplierGridOptions">
                
            </kendo-grid>
        </div>
    </div>

    <script>
        
        var myApp = angular.module("MyApp", ["kendo.directives"])
            .controller("supplierController", function ($scope) {
                height: 400,
                $scope.supplierGridOptions = {
                    height:400,
                    columns: [
                        {field: "Name",title: "Name",width: "120px"}, 
                        {field: "OfficeAdresID",title: "OfficeAdresID", width: "120px"}, 
                        {field: "DeliveryAdresID",width: "DeliveryAdresID"}, 
                        {field: "BillingProfileID", width: "120px"}, 
                        {field: "Title"},
                        { command: "destroy", title: "Delete", width: "110px" }
                    ],
                    pageable: true,
                    sortable: {
                        mode: "multiple",
                        allowUnsort: true
                    },
                    filterable: true,
                    editable: true,
                    toolbar: ["create", "save", "cancel"],
                    dataSource: {
                        type: "aspnetmvc-ajax",
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true,
                        pageSize: 15,
                        schema: {
                            data: "Data",
                            total: "Total",
                            model: {
                                id: "ID",
                                fields: {
                                    Name: { editable: true, type: "string", validation: { required: true } },
                                    OfficeAdresID: { type: "number", editable: false },
                                    DeliveryAdresID: { type: "number", editable: false },
                                    BillingProfileID: { type: "number" },
                                    Title: { type: "string", editable: false }
                                }
                            }
                        },
                        batch: true,
                        transport: {
                            read: {
                                url: "/Home/GetSupplier"
                            },
                        }
                    }
                }
            });
    </script>

     

    And the controller look like this:

     

    public class HomeController : Controller
        {
            private MyContext db = new MyContext();

        [HttpPost]
            public JsonResult GetSupplier([DataSourceRequest] DataSourceRequest request)
            {
                DataSourceResult result = db.Suppliers.ToDataSourceResult(request);
                return Json(result, JsonRequestBehavior.AllowGet);
            }

    }

  5. Laurent
    Laurent avatar
    4 posts
    Member since:
    Aug 2015

    Posted 03 Oct in reply to Nikolay Rusev Link to this post

    Hi There,

    I am evaluating KendoUI using Angular, KendoGrid, with MVC5 but The Sort/Group/Filter is always null in controller regardeless of what i have tried. I read many thread and i believe i am doing what i should do but the value are null. Please let me know what the issue is.

    I have inserted the code in a separate file.

    Laurent

  6. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 04 Oct Link to this post

    Hello Laurent,

    I examined the provided code and as far as I can see it looks correct. For your convenience I prepared a small runnable sample and attached it to this forum post. Could you please check it out and let me know how it differs from your real setup?

    Regards,
    Kostadin
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Laurent
    Laurent avatar
    4 posts
    Member since:
    Aug 2015

    Posted 22 Oct in reply to Kostadin Link to this post

    Hi Kostadin, 

    I have download your example but was missing a valid Kendo.mvc in the package so i used NuGet to update the project. 

    Now the project starts but crash straight after beginning. 

    regards, Laurent

  8. Laurent
    Laurent avatar
    4 posts
    Member since:
    Aug 2015

    Posted 22 Oct in reply to Laurent Link to this post

    Hi Kostadin, 

    I cannot see any difference between my project and your project. To my own interpretation, the only way the DataSourceRequest parameter can be set is from the client side and server side. From the browser the following form data are sent:

    sort:Name-asc~OfficeAdresID-asc
    page:1
    pageSize:15
    group:
    filter:Name~eq~'1'

    Please check this is correct format. Then it is all about the parsing on server side. This is done automatically with the mapping method.

    public JsonResult GetSupplier([DataSourceRequest] DataSourceRequest request)

    Which i have no control over. So what is necessary to make this line work properly?

    Regards, Laurent

  9. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 26 Oct Link to this post

    Hi Laurent,

    Could you please verify that you are including kendo.aspnetmvc.min.js in your project? Also you can check for any client exception which might prevent passing the parameters to the server. I would appreciate if you prepare a small runnable sample and send it to us in order to examine it locally.

    Regards,
    Kostadin
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready