2013-05-09 144 views
15

我想刷新Kendo UI網格,但尚未成功。有人會建議我錯過了什麼或者我做錯了什麼嗎?如何刷新Kendo UI網格

我有以下代碼:

.cshtml:

$('#btnRefresh').click(function (e){ 

      $.ajax({ 
       type: 'POST', 
       url: "@(Url.Content("~/Administration/RefreshAll/"))", 

       success: function() { 
        $("#Product").data("kendoGrid").dataSource.read(); 
        $('#Product').data('kendoGrid').refresh(); 
        //grid.refresh(); 
        location.reload(true); 
       }, 
       error: function(){ 
        $("#btnRefresh").removeAttr('disabled'); 
       } 
      }); 


     }); 

控制器:

public ActionResult RefreshAll([DataSourceRequest] DataSourceRequest request) 
     { 
      db.ProcessAll(); 
      Response.Cache.SetCacheability(HttpCacheability.NoCache); 
      return View(); 
     } 

回答

35

腳本應該

$('#btnRefresh').click(function (e){ 
     var grid = $("#Product").data("kendoGrid"); 
       grid.dataSource.page(1); 
       grid.dataSource.read(); 
     }); 
在控制器 添加引用

  • using Kendo.Mvc.UI;
  • using Kendo.Mvc.Extensions;

的ActionResult應該

public ActionResult RefreshAll([DataSourceRequest] DataSourceRequest request) 
     { 
      //assuming db.ProcessAll() will return a list object 
      return Json(db.ProcessAll().ToDataSourceResult(request)); 
     } 
+0

public void ProcessAll()因此我無法返回JSON – Spidey 2013-05-09 21:49:50

+0

您需要將列表對象傳遞給模型。 – HaBo 2013-05-09 22:22:11

+0

好的。謝謝我將嘗試 – Spidey 2013-05-09 22:25:17