2

我正在发布一个 kendoui 网络网格,它没有发送数据,我看不出我在做什么与失败的样本不同。我正在发布到控制器,但它是空的(如果批处理: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"
            });

网络API:

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

2 回答 2

9

我想通了,虽然我不得不离开这个例子http://demos.kendoui.c​​om /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) ;
                                    }
                                }
于 2013-02-19T03:38:09.497 回答
1

没有像 jsonp + POST 这样的东西 - 在这里讨论。除非你真的知道为什么需要它,否则不要使用 jsonp。

于 2013-02-18T17:13:53.593 回答