我有一个这样定义的网格...
<div id="view">
<div id="grid" data-role="grid"
data-editable="false"
data-columns="[{ 'field': 'Name' }, { 'field': 'Version'}]"
data-bind="source: releases">
</div>
</div>
和这样定义的视图模型...
var viewmodel = kendo.observable({
releases: new kendo.data.DataSource({
schema: {
model: {
id: "Id",
fields: {
Id: { type: "string" },
Name: { type: "string" },
Version: { type: "string" },
CreatedOn: { type: "datetime" }
}
}
},
transport: {
read: {
url: "/Release/Index?handler=List",
type: "jsonp"
}
}
})
});
当我尝试渲染页面时,会显示控件,但没有数据,而是出现400错误。更多阅读内容告诉我有关防伪令牌以及如何在我的帖子请求中设置标题的信息,因此我将其添加到页面顶部。...
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
然后,我用防伪令牌设置呼叫的标题,并将其设置在我的客户端代码中...
$(function () {
const requestVerificationToken = '@Xsrf.GetAndStoreTokens(HttpContext).RequestToken';
const beforeSend = req => req.setRequestHeader('RequestVerificationToken', requestVerificationToken);
const grid = $("#grid").getKendoGrid();
grid.dataSource.transport.options.read.beforeSend = beforeSend;
grid.data.read();
});
现在,当我调用页面时,我得到Cannot read property 'read' of undefined
。
我读过的所有内容都表明我做对了!
我在做什么?