asp.net-mvc - 无法将 JSON 数据绑定(bind)到 KendoUI Grid

标签 asp.net-mvc json kendo-ui

我在尝试将 KendoUi 网格与 Controller 中的 Json 数据绑定(bind)时遇到了某个问题。事情看起来很好,我的 Json 对象包含数据,但网格仍然没有显示任何内容:

我在 Chrome JavaScript 控制台中收到此错误:

GET http://localhost:8084/Records?take=5&skip=0&page=1&pageSize=5 500 (Internal Server Error) 

查看中:

<div id="grid">
</div>
<div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#grid").kendoGrid({
                dataSource: {
                    type: "json",
                    serverPaging: true,
                    pageSize: 5,
                    groupable: true,
                    selectable: "row",
                    transport: { read: { url: "Records", dataType: "json"} }
                },
                height: 400,
                scrollable: true,
                sortable: true,
                filterable: true,
                pageable: true,
                columns: [
                        { field: "No", title: "No" },
                        { field: "Desc", title: "Description" },
                        { field: "priority", title: "Priority" },
                        { field: "decision", title: "Decision" }
                    ],
                dataBound: function () {
                    this.expandRow(this.tbody.find("tr.k-master-row").first());
                }
            });
        });
    </script>

Controller 中:

    public ActionResult GetRecords()
    {
       var obj = new User();
        var jsnRslt = obj.GetResult(Session["id"].ToString());
//return Json(jsnRslt);

        return Json(jsnRslt, JsonRequestBehavior.AllowGet); //Changed as suggested by Dismissile
    }

模型中:

public object GetResult(string usrId)
    {
…
….
…..            try
        {
            int i = 0;
            if (rcrds != null || rcrds.HasRows)
            {
                jsonWriter.WriteStartObject();
                while (rcrds.Read())
                {
                    for (int j = 0; j < rcrds.FieldCount; j++)
                    {
jsonWriter.WritePropertyName(rcrds.GetName(j));
jsonWriter.WriteValue(rcrds.GetValue(j));
                    }
                    i++;
                }
                jsonWriter.WriteEndObject();
            }

        }

        catch (Exception ex) { }
        return jsonWriter;
    }
}

请帮忙。

最佳答案

您可能在 JSON 调用中需要这个:

return Json(jsnRslt, JsonRequestBehavor.AllowGet);

看起来您正在执行 GET 调用,但默认情况下 JSON 调用不允许使用 GET。

关于asp.net-mvc - 无法将 JSON 数据绑定(bind)到 KendoUI Grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15616757/

相关文章:

c# - MVC Controller 未绑定(bind) ViewModel

json - 从 API 解码 JSON - Swift 5

java - 向 JSON 无缝添加新字段

php - 使用 Kendo Upload 的 Kendo Grid 内联编辑返回空结果

asp.net - ASP.NET 中的国际化如何工作?

javascript - 预计项目文件

json - 在 JSON 的情况下,当模式推断留给 Spark 时,为什么 Spark 会输出 nullable = true?

kendo-ui - 您可以禁用对 KendoUI Grid 中特定单元格或列的选择吗?

jquery - kendo ComboBox 查找并选择值(如果存在)

c# - MVC 4 Entity Framework 不从SQL Server获取数据库