Kendo ui 如何在ajax post回调后刷新KendoUi网格

Kendo ui 如何在ajax post回调后刷新KendoUi网格,kendo-ui,kendo-grid,kendo-asp.net-mvc,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,在ajax发布成功后,如何刷新kendoui网格? 以下是我的网格ajax帖子: var newUser = { UserId: 0, UserLoginName: currentRecord.UserLoginName, UserDisplayName: currentRecord.UserDisplayName };

在ajax发布成功后,如何刷新kendoui网格? 以下是我的网格ajax帖子:

 var newUser = {
                    UserId: 0,
                    UserLoginName: currentRecord.UserLoginName,
                    UserDisplayName: currentRecord.UserDisplayName
                };
                //insert selected rows using DataSource insert method
                destinationGrid.dataSource.insert(newRecord);
                //ajax post to server
                var url = '@Url.Action("CreateUser", "ManageUsers")';
                $.post(url, { loginid: currentRecord.UserLoginName, name: currentRecord.UserDisplayName, role: roleSelected }, function (result) {
                    if (result.Success) {
        **////grid is not refreshing as I want to refersh the grid again from database**
                        destinationGrid.dataSource.read();
                    }

                });
            }
试用

$("#gridName").data("kendoGrid").dataSource.read();

这只是一个例子

 $.ajax({
          url: '@Url.Action("NewGridView", "Test")',
          type: "Post",
          data: { sampleItem: sampleItem, sampleCode: sampleCode, sampledescription: sampledescription },
          dataType: 'json',
          success: function (result) {

     $('#gridName').data("kendoGrid").dataSource = new kendo.data.DataSource({ data: result });
     $('#gridName').data("kendoGrid").dataSource.read();
     $('#gridName').data("kendoGrid").refresh();
}
});
控制器

 public JsonResult NewGridView(string sampleItem, string sampleCode, string sampledescription)
        {

        List<SampleModel> sampleAddList = new List<SampleModel>();
        SampleModel sampleAdd = new SampleModel();
        sampleAdd.SampleCode = sampleCode;
        sampleAdd.SampleDescription = sampledescription;
        sampleAdd.SampleItems = sampleItem;

        sampleAddList.Add(sampleAdd);
        var result = sampleAddList;
       return Json(result, JsonRequestBehavior.AllowGet);
}
公共JsonResult NewGridView(字符串sampleItem、字符串sampleCode、字符串sampledescription) { List SAMDLIST=新列表(); SampleModel Sampled=新的SampleModel(); SampleCode=SampleCode; SampleDescription=SampleDescription; SampleItems=sampleItem; samconceddlist.Add(samconced); var结果=样本列表; 返回Json(结果,JsonRequestBehavior.AllowGet); } 如果您需要在Complete controller操作完成后立即刷新网格


$('#gridName').data(“kendoGrid”).dataSource=new kendo.data.dataSource({data:result})在您的
成功发布中

据我所知,您需要在成功更新后刷新剑道网格(相当于$.ajax
成功:
回调),对吗

在这种情况下,剑道网格没有任何成功回调,而是使用
complete
回调。在运输过程中尝试以下方法

dataSource: {
        transport: {
            read: {
                url: "/YourController/LoadYourGridData",
                type: "POST",
                contentType: "application/json",
                dataType: "json"
            },
            update: {
                url: "/YourController/UpdateYourGridData",
                contentType: "application/json; charset=utf-8",
                type: "POST",
                dataType: "json",
                complete: function (data) {

                    $("#Grid").data("kendoGrid").dataSource.read();

                }
            }
        }

如果您在我的网格中看到上面的内容,请参见此。我已经在使用它,并且我已经尝试了下面的两个选项。下面的选项在任何地方和任何事件中都有效,因为我已经多次使用它,但是在$(post(url)中回调我需要在完成控制器操作后立即引用网格。我如何做?我只是发布代码。我希望它可以帮助您。您应该为此使用传输配置,创建url。在数据源中插入新项后,只需调用sync()让魔法发生吧。感谢它起作用了,但是新添加的行将位于表的底部,我如何才能在第一行创建它?@Deepali我想你必须按照控制器中创建的日期描述来做顺序..可编辑(可编辑=>Editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Top))将确保在顶部插入新行
dataSource: {
        transport: {
            read: {
                url: "/YourController/LoadYourGridData",
                type: "POST",
                contentType: "application/json",
                dataType: "json"
            },
            update: {
                url: "/YourController/UpdateYourGridData",
                contentType: "application/json; charset=utf-8",
                type: "POST",
                dataType: "json",
                complete: function (data) {

                    $("#Grid").data("kendoGrid").dataSource.read();

                }
            }
        }