2014-02-17 122 views
0

我正在開發一個KendoUI網格,內嵌可編輯選項在JavaScript中,並且無法使更新按鈕觸發單擊事件並將數據發佈到服務器端更新事件。點擊更新按鈕甚至不會更新客戶端上的網格。Kendo UI網格更新按鈕沒有觸發

希望有人能幫助我指出我在這裏做錯了什麼。

這不是重複的,因爲我厭倦了答案中的jfiddle鏈接,它不工作。 kendo UI grid update function wont fire

<div id="grid"></div> 

@section Scripts{ 

<script type="text/javascript"> 

    $(function() { 
     var dataSource = new kendo.data.DataSource({ 
      transport: { 
       read: { 
        url: "Home/GetPupilsAsJson", 
        dataType: 'json' 
       },      
       update: { 
        url: "Home/UpdatePupils", 
        dataType: 'json', 
        type: 'POST' 
       } 
      }, 
      pageSize: 5, 
      autoSync: true     
     }); 

     $('#grid').kendoGrid({ 
      dataSource: dataSource, 
      editable: "inline", 
      pageable: true, 
      columns: [{ 
       field: "Id", 
       title: "Id", 
       width: 150, 
       hidden: true 
      }, { 
       field: "Firstname", 
       title: "Firstname", 
       width: 150 
      }, { 
       field: "Lastname", 
       title: "Lastname", 
       width: 150 
      }, { 
       field: "DateOfBirth", 
       title: "DateOfBirth", 
       width: 150 
      }, { 
       field: "Class", 
       title: "Class", 
       width: 150 
      }, { 
       field: "Year", 
       title: "Year", 
       width: 150 
      }, 
      { 
       command: ["edit"], 
       width: 150 
      }] 
     });  
    }); 
</script>  
} 

的HomeController

public ActionResult GetPupilsAsJson() 
    {    
     return Json(GetPupils(), JsonRequestBehavior.AllowGet); 
    } 

[AcceptVerbs(HttpVerbs.Post)] 
    [HttpPost] 
    public void UpdatePupils(Pupil p) 
    { 
      //never reach here 
    } 
+0

你可以在UpdatePupils中試試沒有參數'Pupil p'並告訴我程序到達了嗎? – MustafaP

+0

@MustafaP ..我厭倦了你的建議,仍然無法正常工作。事實上,我的問題是更新按鈕甚至沒有關閉客戶端上的編輯字段。我嘗試用MVC包裝它工作正常,但我們沒有許可證的包裝不幸的。 – lawphotog

+0

如果您的瀏覽器處於'Developer Mode'或'inspection'並且您檢查網絡流量,您是否看到有任何請求會看到請求通過?我的意思是,你的瀏覽器調用'Home/UpdatePupils'嗎? – OnaBai

回答

3

我不知道爲什麼,但通過放置架構信息來修復它。

schema: { 
     model: { 
      id: "Id", 
      fields: { 
       Firstname: { editable: true, validation: { required: true } }, 
       Lastname: { validation: { required: true } }, 
       DateOfBirth: { validation: { required: true } }, 
       Class: { validation: { required: true } }, 
       Year: { validation: { required: true } } 
      } 
     } 
    } 
+0

謝謝,如果你有一個kendo數據源對象,好像你需要指定模式以便觸發更新功能。 – emp

0

使用@Url.Action("GetPupilsAsJson", "Home")'因此沒有必要通過base url在這樣BASEURL+ "Home/GetPupilsAsJson"你的更新動作。

var dataSource = new kendo.data.DataSource({ 
      transport: { 
       read: { 
        url: '@Url.Action("GetPupilsAsJson", "Home")', 
        dataType: 'json' 
       },      
       update: { 
        url:'@Url.Action("UpdatePupils", "Home")', 
        dataType: 'json', 
        type: 'POST' 
       } 
      }, 
      pageSize: 5, 
      autoSync: true     
     }); 
+0

謝謝,但仍然無法正常工作。 – lawphotog

+0

@lawphotog你有任何建議使用Kendo MVC調用更新和取消選項。 http://stackoverflow.com/questions/38786267/inline-editing-is-not-working-in-kendo-mvc – Steve

0

使用參數映射來傳遞模型值

<script type="text/javascript"> 

    $(function() { 
     var dataSource = new kendo.data.DataSource({ 
      transport: { 
       read: { 
        url: '@Url.Action("GetPupilsAsJson", "Home")',, 
        dataType: 'json' 
       },      
       update: { 
        url: '@Url.Action("UpdatePupils", "Home")', 
        dataType: 'json', 
        type: 'POST' 
       }, 
       parameterMap: function (options, operation) { 
        if (operation !== "read" && options.models) { 
         return { models: kendo.stringify(options.models) }; 
         } 
       } 
      }, 
      pageSize: 5, 
      autoSync: true     
     }); 

呼叫控制器與parameterMap的

public JsonResult UpdatePupils(string models) 
     { 

      return Json(..); 
     } 
0

是任何你的文字有一個像<> HTML標記,刪除它們,然後點擊在更新。更新事件將觸發。