2015-09-01 50 views
1

在嘗試執行批量更新時,我無法將值發佈到MVC WEB API控制器,也無法獲得mu PUT控制器中的記錄ID。 我已經訪問了一些鏈接,可以解決同樣的問題,但沒有解決方案。在Kendo UI GRID中執行批量更新不起作用

$(document).ready(function() { 
     debugger; 
     var webapiUrl = (My webapi); 

     dataSource = new kendo.data.DataSource({ 
         type: "json", 
         transport: { 
          read: { 
           url: webapiUrl + api/GetProductsByShipID/1", 
           contentType: "application/json", 

          }, 
          update: { 
           url: webapiUrl + api/OpportunityProducts/1", 

           contentType: "application/json", 
           type: "PUT" 
          }, 
          destroy: { 
           url: webapiUrl + /api/OpportunityProducts/", 
           contentType: "application/json", 
           type: "DELETE" 
          }, 
          create: { 
           url: webapiUrl + /api/OpportunityProducts/", 
           contentType: "application/json", 
           type: "POST" 
          }, 
          parameterMap: function (options, operation) { 
           if (operation !== "read") { 
            return options; 
           } 
          } 

         }, 
         batch: true, 
         pageSize: 10, 
         schema: { 
          model: { 
           id: "ID", 
           fields: { 
            ID: { editable: false, nullable: true }, 
            ProductDesc: { type: "string" }, 
            Quantity: {type: "number"}, 
            UnitPrice: { type: "number"} 
           } 
          } 

        }); 

       $("#grid").kendoGrid({ 
        dataSource: dataSource, 
        navigatable: true, 
        pageable: true, 
        toolbar: ["create", "save", "cancel"], 
        columns: [ 
         "ProductName", 
         { field: "ProductDesc", title: "Product Desc"}, 
         { field: "Quantity", title: "Quantity" }, 
         { field: "UnitPrice", width: 120 }, 
         { command: "destroy", title: " ", width:150 }], 
        editable: true 
       }); 
      }); 
     </script> 
+0

那麼,什麼是被髮送到你的API,當你檢查身體。使用像小提琴手一樣的東西。同樣在你的代碼示例中,它看起來像缺少圍繞'/ api/OpportunityProducts /' –

+0

的開頭引用謝謝你的評論,下面是對這個問題的回答。在這裏複製網址時,報價錯誤是一個錯字。 –

回答

0

好了經過一些解決方法後,深夜,我能夠修改我的劍道網格的參數映射部分,這導致了我的預期輸出。

這是我更新了我的parameterMap的部分...

上一頁

parameterMap: function (options, operation) { 
         if (operation !== "read") { 
          return options; 
         } 
        } 

更新

parameterMap: function (options, operation) { 
          debugger; 
          if (operation !== "read" && options.models) { 
        var webapiUrl = (my webapi); 
         var i = 0; 
         for (i = 0; i < options.models.length; i++) { 
          $.ajax({ 
           cache: false, 
           async: true, 
           type: "PUT", 
           url: webapiUrl + "/api/OpportunityProducts/" + options.models[i].Id, 
          data: { 

          ID: options.models[i].ID, 
          ProductDesc: options.models[i].ProductDesc, 
            Quantity: options.models[i].Quantity 
          }, 

           success: function (data) { 

           }, 

           error: function (jqXHR, exception) { 

            alert(exception); 

           } 

          }); 

         }