2013-02-18 65 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