簡體   English   中英

Kendo網格將數據作為空發布回控制器

[英]Kendo grid posting the data back to controller as null

當我嘗試將整個kendo網格發布回時,我沒有在控制器中收到該對象,該對象為null。 我在工具欄上添加了一個自定義按鈕,當我單擊它時,它應該返回一個帖子。 提琴手請求顯示正在回發的數據,但是我無法在控制器中接收到它?

這是從提琴手,HTTP POST請求中捕獲的

POST http:// localhost:59457 / api / data / SaveBill HTTP / 1.1主機:localhost:59457連接:keep-alive內容長度:24接受:application / json,text / plain, /來源: http:// localhost :59457用戶代理:Mozilla / 5.0(Windows NT 6.1; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 48.0.2564.116 Safari / 537.36內容類型:application / json; charset = UTF-8引用者: http:// localhost:59457 / Accept-Encoding:gzip,deflate Accept-Language:zh-cn,en; q = 0.8

[{“ Id”:1,“ Name”:“ John”}]

我的控制器上的代碼

  public IHttpActionResult SaveBillingGroupMap([FromBody]test models)
        {
            var x = HttpContext.Current.Request.InputStream;
            //var employees = this.DeserializeObject<IEnumerable<test>>("models");
            throw new NotImplementedException();
        }

  public class test
        {
            public int Id { get; set; }

            public string Name { get; set; }
}

JS上的代碼(角)

     $scope.mockdata = new kendo.data.ObservableArray([{
            "Id": 1,
                "Name": "John"
                }, {
                "Id": 2,
                "Name": "Joe"
                }, {
                "Id": 3,
                "Name": "Jack"
                }]);

                    $scope.sportsGrid = new kendo.data.DataSource({
                    // data: $scope.mockdata,
                    transport: {
                        read: function (e) {
                            e.success($scope.mockdata);
                },
                    update: function (e) {
                                console.log("Update", e);
                                },
                                        destroy: function(e) {
                                console.log("Destroy", e);
                        },
                                    create: function(e) {
                        console.log("Create", e);
                    },
                                    parameterMap: function (options, operation) {
                                if (operation !== "read" && options.models) {
                                    return {
                                        models: kendo.stringify(options.models)
                        };
                        }
                        }
                        },
                            batch: false,
                                            pageSize: 5,
                            change: function (e) {
                        console.log("change: " +e.action);
                        if (e.action === "remove") {
                                                    this.sync();
                                        }
                            // do something with e
                        },
                                schema: {
                                            model: {
                                    id: "Id",
                                    fields: {
                                    Id: {
                                        type: "number"
                                        },
                                        Name: {
                                        type: "string"
                                        }

                                    }
                                    }
                                        }
                                    });



   $scope.options = {
                sortable: true,
                    pageable: true,
                editable: true,
                toolbar: ["create", "cancel", {
                    text: "Custom"
            }],
                columns: [{
                field: "Id",
                    title: "ID"
        }, {
            field: "Name",
            title: "Name"
        }, {
                    command: ["destroy"],
                        title: " ",
                            width: "150px"
                        }],
                    edit: function(e) {
            if (e.model.Name == "Joe") {
                this.closeCell();
                }

        }

                };
    $("#sportsSetupGrid").on("click", ".k-grid-Custom", function (e) {
        var models = JSON.stringify($("#sportsSetupGrid").data().kendoGrid._data);


        $http({
        method: 'POST',
        url: 'api/data/SaveBill',
        data: models,
        contentType: "application/json",
            dataType:"JSON"

    });
            e.preventDefault()
            });

這是在HTML上

     <div kendo-grid k-options="options" k-data-source="sportsGrid" id="sportsSetupGrid" ></div>

您正在javascript中調用操作方法SaveBill ,而控制器中的操作方法名稱為SaveBillingGroupMap 更正此錯誤,它將是控制器中的方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM