Completed
Last Updated: 11 Jan 2021 14:49 by ADMIN
Ivan
Created on: 04 Sep 2013 20:31
Category: UI for ASP.NET MVC
Type: Feature Request
23
OData support for Kendo UI ASP.NET MVC Server Wrappers
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
            )
        )
)
3 comments
ADMIN
Alex Hajigeorgieva
Posted on: 11 Jan 2021 14:49

Hello,

To bind to odata, you can use the Custom() data source method with the Type() method:

.DataSource(ds => ds.Custom().Type("odata")

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Thomas
Posted on: 03 Jul 2015 11:34
Here is a reply I got from Telerik when asking them about OData. Razor was not mentioned.

Q)
Where do you see OData going? Will this be the long-term strategy for Telerik?
A)
We plan to continue support for OData as a viable datasource for our web based Platform UI toolkits. We have configured the Kendo UI DataSource to easily bind to OData. See "Creating a DataSource for Remote Data" for sample code that demonstrates binding to OData. And, the same is the case with our UI for ASP.NET AJAX toolkit. As an example, see "ODataDataSource Overview". 
Ivan
Posted on: 04 Sep 2013 20:33
@(Html.Kendo().Grid<Album>()
    .Name("gridX")
    .DataSource(dataSource => dataSource
        .OData  // Instead of .Ajax()