2

I'm posting a kendoui web grid and it isn't sending data and I can't see what I'm doing different from the sample that's failing. I'm posting to the controller, but it's either empty (if batch: true or null if batch: 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"
            });

the web 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;
        }
James Fleming
  • 2,589
  • 2
  • 25
  • 41
  • Most probably your question is sort of http://stackoverflow.com/questions/22622061/why-are-my-kendogrid-update-parameters-always-null-in-the-controller/24261775#24261775 , you can find help there – Gyanesh Jun 17 '14 at 10:57

2 Answers2

9

I'd figured it out, although I had to depart from the example http://demos.kendoui.com/web/grid/editing-popup.html

The fix was add the content type, correctly use dataType: "json" as noted above, change from batch: true to batch: false and change the parameter map to the below

 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) ;
                                    }
                                }
James Fleming
  • 2,589
  • 2
  • 25
  • 41
1

There is no such thing as jsonp + POST - it is discussed here. Do not use jsonp unless you really know why you need it.

Community
  • 1
  • 1
Petur Subev
  • 19,983
  • 3
  • 52
  • 68
  • Good catch, and you are quite correct, I've corrected my example, but the delete method was properly configured. I did figure it out, after stepping away. However that was not the answer. I will post the correct answer below. – James Fleming Feb 19 '13 at 02:05