简体   繁体   中英

Passing KENDO Grid data view to MVC controller

I have an issue sending Telerik Kendo Grid viewdata to MVC Controller. I've tried to make ViewModel etc but i just can't figure this one out.

Here is my code to populate grid:

 var grid = $("#grid").kendoGrid({
                            dataSource: {
                                data: kontdata.Data,
                                schema: {
                                    model: {
                                        fields: {
                                            Id: { type: "number", editable: false },
                                            Name: { type: "string" },
                                            Number: { type: "string" },
                                            Info: { type: "string" },
                                            Email: { type: "string" },
                                            Category: { type: "string" },
                                            MarketingAllowed: { type: "number", editable: false },
                                            AddedDate: { type: "date", editable: false }
                                        }
                                    }
                                },
                                pageSize: 20
                            },
                            height: 500,
                            scrollable: true,
                            toolbar: kendo.template($("#template").html()),
                            serveroperation: false,
                            sortable: true,
                            editable: { mode: "incell", confirmation: false },
                            selectable: "row",
                            filterable: true,
                            pageable: true,
                            columns: [
                                {
                                    field: "Name",
                                    title: "Nimi"
                                },
                                {
                                    field: "Number",
                                    title: "Numero"
                                },
                                {
                                    field: "Info",
                                    title: "Info"
                                },
                                {
                                    field: "Email",
                                    title: "Email"
                                },
                                {
                                    field: "Category",
                                    title: "Kategoria"
                                },
                                {
                                    field: "MarketingAllowed",
                                    title: "Markkinointikielto",
                                    width: "160px"
                                },
                                {
                                    field: "AddedDate",
                                    title: "LisättyPvm",
                                    format: "{0:dd/MM/yyyy HH:mm:ss}"
                                },
                                {
                                    command: [
                                        { name: "destroy", text: "Poista", width: "70px" }
                                    ]
                                }
                            ]
                        }).data("kendoGrid");

And here is the code to post grid view data:

function tallennagridi() {
        var griddata = $("#grid").data("kendoGrid");

        $.ajax(
               {
                   type: 'POST',
                   url: '/Contactlist/Savegriditems/',
                   dataType: 'json',
                   contentType: "application/json; charset=utf-8",
                   data: JSON.stringify({ griditems: griddata.dataSource.view() }),
                   success: function (result) {
                       alert('success');
                   }
               });
    };

And here is the controller:

public JsonResult Savegriditems([DataSourceRequest] DataSourceRequest request, CustomerViewModel griditems)
    {
        var joku = griditems;

        return Json(joku, "Content-type: text/x-json; charset=utf-8", JsonRequestBehavior.AllowGet);
    }

Any help would be appreciated.

Br.Eero

我的错误, CustomerViewModel gridItems应该是:

CustomerViewModel[] gridItems;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM