OData support for Kendo UI ASP.NET MVC Server Wrappers
@* OData support for Kendo UI ASP.NET MVC Server Wrappers *@
@(Html.Kendo().Grid<Album>()
.Name("gridX")
.DataSource(dataSource => dataSource
.Ajax()
//.OData // Instead of .Ajax()
// Results:
// - dataSource.type = 'odata' instead of 'aspnetmvc-ajax' set by .Ajax()
// - dataSource.schema.data = function (data) { return data.value; } - data source will be bound to the ODate values field
// - dataSource.schema.total = function (data) { return data['odata.count']; } - The total item count is in OData odata.count field
.Read(read => read.Url(albumUrl).Type(HttpVerbs.Get)
.Local() // Result: dataSource.transport.options.read.dataType = 'json'; (Default value: 'jsonp')
)
.Create(create => create.Url(albumUrl).Type(HttpVerbs.Post))
.Update(update => update.Type(HttpVerbs.Put)
.Url(x => _albumUrl + x.Id;) // Instead of .Url(albumUrl)
// Result: dataSource.transport.options.update.url = function (data) { return _albumUrl + data.Id; };
// Note: WebAPI needs the ID of the entity to be part of the URL e.g. PUT /api/Album/1
)
.Destroy(destroy => destroy.Type(HttpVerbs.Delete)
.Url(x => _albumUrl + x.Id;) // Instead of .Url(albumUrl)
// Result: dataSource.transport.options.destroy.url = function (data) { return _albumUrl + data.Id; };
// Note: WebAPI needs the ID of the entity to be part of the URL e.g. DELETE /api/Album/1
)
)
)