我为我的剑道MVC网格创建了自定义数据源。 Everythink正在运行,数据从服务器返回。但在网格中只显示空单元格。就像在这张图片上: MVC网格代码:
@(Html.Kendo().Grid<PageViewModel>()
.Name("pageGrid")
.Columns(columns =>
{
columns.Bound(item => item.Name).Width(100);
})
.DataSource(dataSource => dataSource.Custom()
.Type("aspnetmvc-ajax")
.PageSize(10)
.ServerPaging(true)
.ServerSorting(true)
.ServerFiltering(true)
.Transport(transport => transport
.Read("ReadPages", "Page")
)
.Schema(schema => schema
.Data("result.data")
.Total("result.total")
.Errors("result.errors")
.Model(m => m.Id(p => p.Name))
)
)
)
当我使用javascript执行相同操作时,它会工作并显示数据。
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "@Url.Action("ReadPages", "Page")",
type: "post",
dataType: "json"
}
},
schema: {
data: "result.data",
total: "result.total"
}
});
var grid = $("#pageGrid2").kendoGrid({
dataSource: dataSource
});
问题出在哪里?谢谢!
编辑:我收到了这个回复: {
"success": true,
"result": {
"data": [
{
"id": "1",
"name": "Test",
"content": "Test obsahu",
"url": "test",
"title": "test",
"description": "test"
},
{
"id": "7",
"name": "Jmeno",
"content": "htmlfdgsrg erg erger",
"url": "test2",
"title": "test",
"description": "Desc grid"
}
],
"total": 2,
"aggregateResults": null,
"errors": null
},
"error": null,
"unAuthorizedRequest": false
}
答案 0 :(得分:1)
也许客户端和服务器端之间的属性名称不匹配,试试这个:
.Model(m =>
{
m.Id(p => p.Name);
m.Field(p => p.Name).From("name");
})