0

我的控制器是这样的:

        [HttpPost]
    public ActionResult Error_Search([DataSourceRequest] DataSourceRequest request, object[] ParaSearch)
    {
        object[] obj = new object[5];
        obj[0] = Convert.ToInt32(ParaSearch[0]);
        obj[1] = ParaSearch[1].ToString();
        obj[2] = Convert.ToDateTime(ParaSearch[2]).AddDays(-10);
        obj[3] = Convert.ToDateTime(ParaSearch[3]);
        obj[4] = ParaSearch[4];
        List<Vsoft.Lists.Model.SYS.SYS_Error> lst = new List<Vsoft.Lists.Model.SYS.SYS_Error>();
        ResultMessage result = new Vsoft.Lists.DALEntity.SYS.DAL_Error().SelectToList(ref lst, obj);
        return Json(lst.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

它将正确返回 Json(lst).. 但我无法将它绑定到数据源并在 Ajax 调用之后刷新 Grid,如下所示:

var requestData = { ParaSearch: arrObject };
    $.ajax({
        url: '@Url.Content("~/Error/Error_Search")',
            data: JSON.stringify(requestData),
            type: 'POST',
            traditional: true,
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            error: function (xhr) {
                result = false;
                alert('Error: ' + xhr.statusText);
            },
            success: function (lst) {
                 var grid = $("#Grid").data("kendoGrid");
                 grid.dataSource.data(lst);
                 grid.refresh();
            },
            async: true,
            processData: false,
            cache: false
        });

AnyOne 可以帮我解决这个问题吗?谢谢大家!

4

1 回答 1

0

如果 ajax 返回足够好,那么使用setDatasource api 调用应该是你的朋友。

success: function (lst) {
                 var grid = $("#Grid").data("kendoGrid");
                 var dataSource = new kendo.data.DataSource({
                          data: lst });
                 grid.setDataSource(dataSource);                 
            }

编辑:使用读取(读取只是包装器$.ajax)希望您已将网格配置为:

.DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Read(read => read.Action("Error_Search", "Error", new { ParaSearch = []}))
         )

然后,从哪里连接一些事件,ParaSearch并将读取调用用作:

<script>
    function someEvent(e) {
        var requestData = { ParaSearch: arrObject };
        grid.dataSource.read(requestData);
    }
</script>
于 2013-11-07T04:35:40.263 回答