【问题标题】:Kendo UI Grid data is always empty at client-side, when binding it from server side从服务器端绑定时,Kendo UI Grid 数据在客户端始终为空
【发布时间】:2015-02-26 20:46:08
【问题描述】:

我正在从 ASP.NET MVC 绑定 Kendo Grid,如下所示:

        @(Html.Kendo().Grid<My.Web.Models.Generated.CustomerSearch01.CityInfo>()
                    .Name("gridCities")
                    .Columns(columns =>
                    {
                        columns.Bound(c => c.Text).Width(140).Title("City");
                    })
                    .Scrollable()
                    .Selectable(selectable => selectable.Type(GridSelectionType.Row))
                    .BindTo(Model.CitiesList)
                    .DataSource(ds => ds.Server().Model(m => m.Id(p => p.Value)))
        )

效果很好,网格显示在带有数据的页面上,我对上面没有任何问题。但是,使用浏览器开发工具,如果我尝试使用以下语句获取上述网格的数据,则返回空:

jQuery("#gridCities").data("kendoGrid").dataSource.data()

我错过了什么?

提前致谢

解决方案(基于答案):

替换以下内容:

.DataSource(ds => ds.Server().Model(m => m.Id(p => p.Value)))

.DataSource(ds => ds.Ajax().ServerOperation(false).Model(m => m.Id(p => p.Value)))

【问题讨论】:

    标签: kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    您的 Grid 配置为使用 ServerBinding,这意味着 TR / TD 元素是从服务器呈现的。如果您希望在客户端拥有模型的 JavaScript 对象并且不执行单独的 Ajax 请求,请将您的 DataSource 配置为

    ds.Ajax().ServerOperations(false)
    

    这不会执行任何 Ajax 请求,数据将从服务器 int JSON 序列化。

    【讨论】:

    • 我不太懂这个。你能根据你的解释帮我做一个小样本吗?如果可以的话,我真的很感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    相关资源
    最近更新 更多