我在尝试将 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/