json 将KENDO Grid数据视图传递给MVC控制器

xzv2uavs  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(127)

我有一个问题发送Telerik剑道网格视图数据到MVC控制器。我试图使视图模型等,但我只是不能弄清楚这一个。
下面是填充网格的代码:

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

下面是发布网格视图数据的代码:

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

这是控制器:

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

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

任何帮助都将不胜感激。
不列颠埃罗

wbgh16ku

wbgh16ku1#

我的错误,CustomerViewModel gridItems应该是:

CustomerViewModel[] gridItems;

相关问题