2017-04-11 66 views
1

當進行創建,更新或刪除,我需要保存其他形式,並獲得該保存功能的id並通過附加參數id與這些事件附加參數create, update, delete劍道UI經過時創建,更新和刪除

如何

我有我的劇本格如下

$(document).ready(function() { 
        var crudServiceBaseUrl = "https://demos.telerik.com/kendo-ui/service", 
         dataSource = new kendo.data.DataSource({ 
          transport: { 
           read: { 
            url: crudServiceBaseUrl + "/Products", 
            dataType: "jsonp" 
           }, 
           update: { 
            url: crudServiceBaseUrl + "/Products/Update", 
            dataType: "jsonp" 
           }, 
           destroy: { 
            url: crudServiceBaseUrl + "/Products/Destroy", 
            dataType: "jsonp" 
           }, 
           create: { 
            url: crudServiceBaseUrl + "/Products/Create", 
            dataType: "jsonp" 
           }, 
           parameterMap: function(options, operation) { 
            if (operation !== "read" && options.models) { 
             return {models: kendo.stringify(options.models)}; 
            } 
           } 
          }, 
          batch: true, 
          pageSize: 20, 
          schema: { 
           model: { 
            id: "ProductID", 
            fields: { 
             ProductID: { editable: false, nullable: true }, 
             ProductName: { validation: { required: true } }, 
             UnitPrice: { type: "number", validation: { required: true, min: 1} }, 
             Discontinued: { type: "boolean" }, 
             UnitsInStock: { type: "number", validation: { min: 0, required: true } } 
            } 
           } 
          } 
         }); 

        $("#grid").kendoGrid({ 
         dataSource: dataSource, 
         pageable: true, 
         height: 550, 
         toolbar: ["create"], 
         columns: [ 
          { field:"ProductName", title: "Product Name" }, 
          { field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "120px" }, 
          { field: "UnitsInStock", title:"Units In Stock", width: "120px" }, 
          { field: "Discontinued", width: "120px" }, 
          { command: ["edit", "destroy"], title: " ", width: "250px" }], 
         editable: "popup" 
        }); 
       }); 

我發現了一些here但是這看起來不正確

我需要將其發佈到

[HttpPost] 
    public JsonResult Add(Product product, int categoryId) 
    { 

    } 

回答

0

只需在內部parameterMap變化return語句來此,這樣它會返回的categoryId

return kendo.stringify({ 
    models: options.models, 
    categoryId: categoryIdFromSomewhere 
)}; 

小紙條,我用JSON.stringify,但相當蘇特如果這會有所作爲。

+0

如果categoryIdFromSomewhere返回0或拋出錯誤,我可以停止該事件嗎? – HaBo

+0

對不起,從來沒有嘗試過......但你可以隨時檢查點擊事件 –