asp.net-web-api - Kendo 网格发布和删除将 null 发送到 Controller

标签 asp.net-web-api kendo-ui kendo-grid

我正在发布一个 kendoui 网络网格,它没有发送数据,而且我看不出我在做什么与 sample 有什么不同。那是失败的。我发布到 Controller ,但它要么是空的(如果批处理:true 或 null,如果批处理:false)

  var crudServiceBaseUrl = "api/Certifications/",
                dataSource = new kendo.data.DataSource({
                    transport: {
                        read:  {
                            url: crudServiceBaseUrl + member.id,
                            dataType: "json"
                        },
                        update: {
                            url: crudServiceBaseUrl,
                            type: "Post",
                            dataType: "json"
                        },
                        destroy: {
                            url: crudServiceBaseUrl,
                            type: "Delete",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        create: {
                            url: crudServiceBaseUrl,
                            type: "Post",
                            dataType: "json"
                        },
                        parameterMap: function (options, operation) {
                            if (operation !== "read" && options.models) {
                                return {models: kendo.stringify(options.models)};
                            }
                        }
                    },
                     editable: { //disables the deletion functionality
                     update: true,
                     destroy: true
                  },
                 batch: true,
                    pageSize: 30,
                    schema: {
                        model: {
                            id: "Id",
                            fields: {
                                Id: { editable: false, nullable: true },
                                MemberId: { editable: false, nullable: true },
                                Name: { validation: { required: true} },
                                AuthorityName: { validation: { required: true} },
                                StartDate: { type: "date", validation: { required: true} },
                                EndDate: { type: "date" }
                            }
                        }
                    }
                });

                $("#certifications").kendoGrid({
                dataSource: dataSource,
                pageable: true,
                height: 300,
                toolbar: ["create"],
                columns: [
                    { field: "Name", title: "Product Name", width: 250 },
                    { field: "AuthorityName", title: "Authority", format: "{0:c}", width: "140px" },
                    { field: "StartDate", title: "Earned", template: '#= kendo.toString(StartDate,"MM/dd/yyyy") #', width: 50 },
                    { field: "EndDate", title: "Expired", template: '#= kendo.toString(EndDate,"MM/dd/yyyy") #', width: 50 },
                    { command: ["edit", "destroy"], title: " ", width: "130px" }],
                editable: "popup"
            });

网络接口(interface):

 public Certification DeleteCertification(CertificationVm cert)
        {
            var model = Uow.Certifications.Get(cert.Id);
            if (model == null)
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NoContent));
            Uow.Certifications.Delete(model);
            Uow.Commit();
            return model;
        }

最佳答案

虽然我不得不偏离示例 http://demos.kendoui.com/web/grid/editing-popup.html,但我已经弄清楚了

修复是添加内容类型,正确使用 dataType: "json"如上所述,从 batch: true 更改为 batch: false 并将参数映射更改为以下

 destroy: {
                                    url: crudServiceBaseUrl,
                                    type: "Delete",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json"
                                },



parameterMap: function (model, operation) {
                                    if (operation !== "read" && model) {
                                        return  kendo.stringify(model) ;
                                    }
                                }

关于asp.net-web-api - Kendo 网格发布和删除将 null 发送到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14928441/

相关文章:

asp.net-web-api - 如何编写 REST API 以使用 ASp.net Web Api 通过 Twilio Number 接收短信

javascript - 下载 PowerBI embed 为 PDF

combobox - Kendo ComboBox - 如何根据其 text() 而不是 value() 选择选项?

css - Kendo UI 网格列自动调整大小

jquery - 使用 Selenium/Geb 测试 Kendo UI 网格

asp.net-web-api - 印度铁路列车搜索 API

c# - ISO8601 直接 DateTime 单日解析不正确

asp.net - IIS 记录 200 状态但返回 500 状态

javascript - Bootstrap 3 和 KendoUI 的 Jquery 问题

javascript - 是否可以有多个剑道网格实例