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

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

7 Answers 796 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 22 Mar 2013, 03:42 PM
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!

7 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 26 Mar 2013, 07:41 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
Laurent
Top achievements
Rank 1
answered on 02 Oct 2016, 09:11 AM

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);
        }

}

0
Laurent
Top achievements
Rank 1
answered on 03 Oct 2016, 06:46 AM

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

0
Kostadin
Telerik team
answered on 04 Oct 2016, 02:15 PM
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
0
Laurent
Top achievements
Rank 1
answered on 22 Oct 2016, 06:32 AM

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

0
Laurent
Top achievements
Rank 1
answered on 22 Oct 2016, 07:14 AM

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

0
Kostadin
Telerik team
answered on 26 Oct 2016, 07:05 AM
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.
Tags
Grid
Asked by
Max
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Laurent
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or