jquery - Kendo UI 网格 WebMethod JSON

标签 jquery asp.net json kendo-grid webmethod

我知道已经有很多这样的东西了。 但是,我已经尝试了数十个 SO 帖子/论坛/Kendo UI 网站,但仍然无法使其工作。我对此已经束手无策,任何帮助将不胜感激。

这是我的数据源声明:

    var dataSource = new kendo.data.DataSource({
        transport: {
            read: function(options) {
                    $.ajax( {
                            type: "POST",
                            url:  "DepartmentHome.aspx/GetMembers",
                            data: options.data,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (msg) {
                                options.success(msg.d);
                                alert(msg.d);
                            }
                        });
            }

        },
        pageSize: 20,
        schema: {
            model: {
                fields: {
                    FirstName: { validation: { required: true} },
                    LastName: { validation: { required: true} }
                }
            }
        }
    });

这是我使用数据源的网格声明:

    $("#grid").kendoGrid({
        dataSource: dataSource,
        scrollable: true,
        groupable: false,
        sortable: true,
        pageable: {
            refresh: true,
            pageSizes: true
        },
        height: 430,
        toolbar: ["create"],
        columns: [
            { field: "FirstName", title: "First Name", width: "100px" },
            { field: "LastName", title: "Last Name", width: "100px" },
            { command: ["edit", "destroy"], width: "160px" }
            ],
        editable: {
            mode: "popup",
            confirmation: "Are you sure?"
        }
    });

这是我在数据源声明中调用的 WebMethod 背后的代码:

    [WebMethod]
    public static string GetMembers()
    {
        var serializer = new JavaScriptSerializer();
        string json = serializer.Serialize(new { FirstName = "John", LastName = "Smith" });
        return json; 
    }

我知道它正在访问 WebMethod,因为我放入数据源中的警报显示了正确的数据:

enter image description here

使用 firebug,响应 header 如下所示: enter image description here

实际响应如下所示:
enter image description here

但是网格不显示数据,如下所示: enter image description here

注意:由于某种原因,网格认为右下角有 39 个项目。

我是否遗漏了一些明显的东西? 有没有更简单的方法来做到这一点?

最佳答案

使用数据:“d”而不是数据:options.data

并添加字符串作为架构定义中两个字段的数据类型。

关于jquery - Kendo UI 网格 WebMethod JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18896550/

相关文章:

c# - 如何取消绑定(bind)ObjectDataSource?

javascript toUpperCase 在 Firefox 中不起作用

python - 使用json文档协议(protocol)的spyne客户端是什么?

java - 对象引用的clear()方法是否为空值?

javascript - 修复 asp.net 中 div 的按钮

javascript - jQuery 滚动事件

jQuery - 如何减少重复

javascript - 通过行单击事件传递动态创建的 html 表格行innertext id

java - 将对象插入到 jsonarray 中的特定位置

jQuery 验证器,重置密码字段和消息