我正在尝试刷新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();
}
答案 0 :(得分:36)
你的脚本应该是
$('#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));
}