You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn how to enable the WebAPI binding capabilities of the Telerik UI Grid for {{ site.framework }}."
5
+
slug: htmlhelpers_grid_webapi_binding
7
6
---
8
7
9
-
# WebAPI Editing
8
+
# WebAPI Binding
10
9
11
-
You can implement the CRUD (Create, Read, Update, Destroy) data operations and a [WebAPI](http://www.asp.net/web-api) controller for the Telerik UI Grid for {{ site.framework }}.
10
+
Web API is an application programming interface for a web application or server which utilizes the [HTTP protocol](https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview)for communication. It enables you to make the server-side of the application more monolithic when it comes to establishing communication between clients and websites to have data access.
12
11
13
-
For runnable examples, refer to the [demos on editing of the Grid](https://demos.telerik.com/{{ site.platform }}/grid/webapi).
12
+
For runnable examples, refer to the [demos on WebAPI binding of the Grid component](https://demos.telerik.com/{{ site.platform }}/grid/webapi).
14
13
15
14
> Defining a Schema.Model.Id is mandatory for the proper execution of the Update, Create and Destroy of the Grid.
16
15
16
+
{% if site.mvc %}
17
+
## Setting up the application for WebAPI Binding
18
+
19
+
To ensure that the application is configured for both Web API binding capabilities:
20
+
21
+
1. Configure Web API by calling `GlobalConfiguration.Configure` in the `Application_Start` method.
22
+
```
23
+
public class MvcApplication : System.Web.HttpApplication
1. Create a file named `WebApiConfig.cs` inside the `App_Start` folder and configure the default WebAPI routing convention.
34
+
```
35
+
public static class WebApiConfig
36
+
{
37
+
public static void Register(HttpConfiguration config)
38
+
{
39
+
// Web API configuration and services.
40
+
// Web API routes.
41
+
config.MapHttpAttributeRoutes();
42
+
config.Routes.MapHttpRoute(
43
+
name: "DefaultApi",
44
+
routeTemplate: "api/{controller}/{id}",
45
+
defaults: new { id = RouteParameter.Optional }
46
+
);
47
+
}
48
+
}
49
+
```
50
+
{% endif %}
51
+
52
+
## Adding a Web API Controller
53
+
54
+
{% if site.mvc %}
55
+
To support writing and reading data using WebAPI endpoints, the `ApiController` base class needs to be inherited for a given controller instance.
56
+
57
+
```
58
+
public class TaskController : System.Web.Http.ApiController
59
+
{
60
+
}
61
+
```
62
+
{% else %}
63
+
To support writing and reading data using WebAPI endpoints, the ControllerBase base class needs to be inherited for a given controller instance.
64
+
65
+
```
66
+
[ApiController()]
67
+
[Route("api/[controller]")]
68
+
public class TaskController : BaseController
69
+
{
70
+
}
71
+
```
72
+
{% endif %}
73
+
## Configuring the CRUD Operations
74
+
17
75
{% if site.mvc %}
18
76
1. Create a new ASP.NET MVC 5 application. If you have installed the [Telerik UI for ASP.NET MVC Visual Studio Extensions]({% slug overview_visualstudio_aspnetcore %}), create a Telerik UI for ASP.NET MVC Web application. Name the application `KendoGridWebApiCRUD`. If you decided not to use the Telerik UI for ASP.NET MVC Visual Studio Extensions, follow the steps from the [introductory article]({% slug gettingstarted_aspnetmvc %}) to add Telerik UI for ASP.NET MVC to the application.
19
77
1. Add a new `Entity Framework Data Model`. Right-click the `~/Models` folder in the solution explorer and pick **Add** > **New Item**. Choose **Data** > **ADO.NET Entity Data Model** in the **Add New Item** dialog. Name the model `Northwind.edmx` and click **Next**. This starts the **Entity Data Model Wizard**.
@@ -31,7 +89,7 @@ For runnable examples, refer to the [demos on editing of the Grid](https://demos
31
89

32
90
{% else %}
33
91
1. Add a new class to the `~/Models` folder. The following example uses the `ProductViewModel` name.
34
-
92
+
```
35
93
public class ProductViewModel
36
94
{
37
95
public int ProductID { get; set; }
@@ -42,19 +100,32 @@ For runnable examples, refer to the [demos on editing of the Grid](https://demos
42
100
[UIHint("Integer")]
43
101
public short? UnitsInStock { get; set; }
44
102
}
103
+
```
45
104
{% endif %}
46
105
47
-
1. Open `Controllers/ProductsController.cs`.
48
106
1. Update the `Get` method as demonstrated by The following example.
49
-
{% if site.mvc %}
50
-
public DataSourceResult Get([System.Web.Http.ModelBinding.ModelBinder(typeof (WebApiDataSourceRequestModelBinder))DataSourceRequest request){% else %}
51
-
public DataSourceResult Get([DataSourceRequest]DataSourceRequest request){% endif %}
107
+
108
+
{% if site.mvc %}
109
+
```
110
+
public DataSourceResult Get([System.Web.Http.ModelBinding.ModelBinder(typeof (WebApiDataSourceRequestModelBinder))DataSourceRequest request)
111
+
{
112
+
return db.Products.ToDataSourceResult(request);
113
+
}
114
+
```
115
+
{% else %}
116
+
```
117
+
[HttpGet]
118
+
public DataSourceResult Get([DataSourceRequest]DataSourceRequest request)
52
119
{
53
120
return db.Products.ToDataSourceResult(request);
54
121
}
122
+
```
123
+
{% endif %}
55
124
56
125
1. Update the `Post` method as demonstrated in The following example.
57
-
{% if site.mvc %}
126
+
127
+
{% if site.mvc %}
128
+
```
58
129
public HttpResponseMessage Post(Product product)
59
130
{
60
131
if (ModelState.IsValid)
@@ -75,19 +146,118 @@ For runnable examples, refer to the [demos on editing of the Grid](https://demos
service.Destroy(new ProductViewModel { ProductID = id } );
252
+
}
253
+
catch (DbUpdateConcurrencyException)
254
+
{
255
+
return new NotFoundResult();
256
+
}
257
+
return new StatusCodeResult(200);
258
+
}
259
+
```
260
+
{% endif %}
91
261
92
262
1. In the view, configure the Grid to use the Products WebAPI controller.
93
263
@@ -167,13 +337,12 @@ For runnable examples, refer to the [demos on editing of the Grid](https://demos
167
337
```
168
338
{% endif %}
169
339
170
-
1. Build and run the application.
340
+
## Building the application
171
341
172
-
{% if site.mvc %}
173
-

174
-
{% endif %}
342
+
343
+
The final result is a Grid with configured editing
175
344
176
345
## See Also
177
346
178
-
*[Editing Approaches by the Grid HtmlHelper for ASP.NET MVC (Demos)](https://demos.telerik.com/{{ site.platform }}/grid/editing)
347
+
*[WebApi Binding for the Grid HtmlHelper for {{ site.product }} (Demos)](https://demos.telerik.com/{{ site.platform }}/grid/webapi)
Copy file name to clipboardExpand all lines: docs-aspnet/html-helpers/editors/datetimepicker/integration.md
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,27 @@ To use the DateInput as the input element in a DateTimePicker, enable the [`Date
32
32
33
33
To customize the placeholders of the DateInput use the [`Messages`](api/kendo.mvc.ui.fluent/datetimepickermessagessettingsbuilder) configuration and set the desired DateInput messages.
34
34
35
+
## AutoFill functionality
36
+
37
+
With the DateInput integration enabled, you the AutoFill functionality can also be enabled via the [`autoFill`](api/javascript/ui/datepicker/configuration/autofill) configuration option.
38
+
39
+
```HtmlHelper
40
+
@(Html.Kendo().DateTimePicker()
41
+
.Name("dateTimePicker")
42
+
.DateInput(true)
43
+
.AutoFill(true)
44
+
)
45
+
```
46
+
{% if site.core %}
47
+
```TagHelper
48
+
<kendo-datetimepicker name="datetimepicker"
49
+
date-input="true"
50
+
auto-fill="true" />
51
+
```
52
+
{% endif %}
53
+
54
+
When the AutoFill functionality is enabled you can complete any of the date segments in the DatePicker's DateInput and when the component looses focus the rest of the date will automatically be filled with the corresponding segment of the current date. For example, if the current date is 06 Jul 2023 and the user fills only the day portion as 15 and clicks on another input element the date will be autofilled to 15 Jul 2023.
Copy file name to clipboardExpand all lines: docs/api/javascript/ui/datepicker.md
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,22 @@ The duration of the open animation in milliseconds.
122
122
});
123
123
</script>
124
124
125
+
### autoFill `Boolean`*(default: false)*
126
+
127
+
When enabled, the DatePicker will autofill the rest of the date to the current date when the component loses focus. For example, entering only the date, month or year portion of the date and blurring the component, the missing sections will be automatically completed.
128
+
Requires a [DateInput](/api/javascript/ui/dateinput) for editing the value.
Copy file name to clipboardExpand all lines: docs/controls/datepicker/integration.md
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,23 @@ To use the DateInput as the input element in a DatePicker, enable the [`dateInpu
24
24
25
25
To customize the placeholders of the DateInput set the [`messages.dateInput`](api/javascript/ui/datepicker/configuration/messages.dateinput) configuration.
26
26
27
+
## AutoFill functionality
28
+
29
+
With the DateInput integration enabled, you the AutoFill functionality can also be enabled via the [`autoFill`](api/javascript/ui/datepicker/configuration/autofill) configuration option.
30
+
31
+
```dojo
32
+
<input id="datepicker" />
33
+
34
+
<script>
35
+
$("#datepicker").kendoDatePicker({
36
+
dateInput: true,
37
+
autoFill: true
38
+
});
39
+
</script>
40
+
```
41
+
42
+
When the AutoFill functionality is enabled you can complete any of the date segments in the DatePicker's DateInput and when the component looses focus the rest of the date will automatically be filled with the corresponding segment of the current date. For example, if the current date is 06 Jul 2023 and the user fills only the day portion as 15 and clicks on another input element the date will be autofilled to 15 Jul 2023.
43
+
27
44
## See Also
28
45
29
46
*[JavaScript API Reference of the DatePicker](/api/javascript/ui/datepicker)
0 commit comments