2013-02-18 87 views
2

我发布了kendoui网格,它不发送数据,我看不到我在做什么不同于sample这是失败。我张贴的控制器,但它的要么是空(如果批次:true或NULL如果批:假)Kendo网格发布和删除发送null到控制器

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; 
     } 
+0

最有可能你的问题是有点http://stackoverflow.com/questions/22622061/why-are-my-kendogrid-update-parameters-always-null -in-the-controller/24261775#24261775,你可以在那里找到帮助 – Gyanesh 2014-06-17 10:57:07

回答

8

我想通了,虽然我已经从例子出发http://demos.kendoui.com/web/grid/editing-popup.html

此修复程序是添加的内容类型,正确地使用数据类型:“JSON”如上所述,从批次的变化:真正的批量:虚假和改变参数映射到下面

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

有作为JSONP没有这样的事+ POST - 讨论here。 除非你真的知道你为什么需要它,否则不要使用jsonp。

+0

好的,你是非常正确的,我已经纠正了我的例子,但删除遇到了hod已正确配置。在走开之后,我确实弄清楚了。然而那不是答案。我将在下面发布正确答案。 – 2013-02-19 02:05:11