I have a grid defined like this...
<div id="view"> <div id="grid" data-role="grid" data-editable="false" data-columns="[{ 'field': 'Name' }, { 'field': 'Version'}]" data-bind="source: releases"> </div></div>and a view model defined so...
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" } } })});
When I try and render the page, the controls show, but there is no data, instead I get a 400 error. More reading tells me about anti-forgery tokens and how to set the header on my post request, so I add this to the top of my page....
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
And, I set the header for the call with the anti forgery token, with this in my client side code...
$(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();});
Now when I call my page, I get "Cannot read property 'read' of undefined."
Everything I've read suggests that I'm doing it right!
What am I not doing?