If you have a WebAPI setup to identify which method(s) to use based on the HTTP Request type (Get, Post etc.), is there a quicker/shorter way to define a Kendo UI DataSource than below that is a lot of repetetive/identical code? Perhaps something that we just have to tell about the base URL and datatype, and then it will by itself figure out that a "read:" should use GET, "create:" should use POST etc.
dataSource: {
transport: {
read: {
url: "/api/AccommodationTypeViewModels",
datatype: "json",
type: "GET"
},
create: {
url: "/api/AccommodationTypeViewModels",
datatype: "json",
type: "POST"
},
update:
{
url: function (data) {
return "/api/AccommodationTypeViewModels/" + data.Id;
},
datatype: "json",
type: "PUT"
},
destroy: {
url: function (data) {
return "/api/AccommodationTypeViewModels/" + data.Id;
},
datatype: "json",
type: "DELETE"
}
},
7 Answers, 1 is accepted
Hello Patrik Johansson,
I would suggest to review the following samples that might meet your requirements:
- grid-webapi-crud/ - This is a sample web site which shows how to use ASP.NET WebAPI CRUD with Kendo UI Grid. It uses the Kendo.DynamicLinq NuGet package.
- Use WebAPI with Server-Side Operations example shows how to implement server-side operations using UI for ASP.NET MVC and ToDataSourceResult extension method.
Regards,
Boyan Dimitrov
Telerik
Hello,
I would like to apologize for the broken link.
The following Use WebAPI with Server-Side Operations link should work fine.
Regards,
Boyan Dimitrov
Telerik
Hello,
I would like to apologize for the broken link.
The following Use WebAPI with Server-Side Operations link should work fine.
Regards,
Boyan Dimitrov
Telerik
[/quote]
The link works but I can't see how it relates to my question?
Hello Patrik Johansson,
Actually this example shows how to use the spacial type of the Kendo UI DataSource "webapi":
$(
"#grid"
).kendoGrid({
columns: [
//removed for brevity
],
...
dataSource: {
type:
"webapi"
...
It requires to include a reference to the Kendo.Mvc.UI and Kendo.Mvc.Extensions assemblies (on the server) in order to use the WebApiDataSourceRequestModelBinder as shown in the api controller. This helps to populate the DataSourceRequest request object with information about sorting, filtering and etc.
This object will have all the information you need in order to get the desired portion of the data using the ToDataSourceResult extension method.
Regards,
Boyan Dimitrov
Telerik
Hi,
can this also handle odata-v4 with webapi?
Hello Benjamin,
The Odata 4 with WebAPI controller project shows how to configure the dataSource to communicate with the WebAPI controller through the Odata 4 protocol. Please note that Odata v4 is not fully supported. For more details please refer to the read me file.
Regards,
Boyan Dimitrov
Telerik