Skip to content

Commit 258f12a

Browse files
committed
Sync with Kendo UI Professional
1 parent 63e9256 commit 258f12a

File tree

1 file changed

+78
-57
lines changed
  • docs-aspnet/html-helpers/editors/dropdownlist/binding

1 file changed

+78
-57
lines changed

docs-aspnet/html-helpers/editors/dropdownlist/binding/razor-page.md

Lines changed: 78 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,86 @@ slug: htmlhelpers_dropdownlist_razorpage_aspnetcore
66
position: 3
77
---
88

9-
# ASP.NET Core Razor DropDownList
10-
9+
# DropDownList in Razor Pages
1110
Razor Pages is an alternative to the MVC pattern that makes page-focused coding easier and more productive. This approach consists of a `cshtml` file and a `cshtml.cs` file (by design, the two files have the same name).
12-
1311
You can seamlessly integrate the Telerik UI DropDownList for {{ site.framework }} in Razor Pages applications.
12+
This article describeshow to configure the DropDownList component in a Razor Pages scenario.
13+
For the complete project, refer to the [DropDownList in Razor Pages example](https://github.com/telerik/ui-for-aspnet-core-examples/tree/master/Telerik.Examples.RazorPages/Telerik.Examples.RazorPages/Pages/DropDownList).
1414

15-
This article describes how to configure the ASP.NET Core Razor DropDownList in a Razor Pages scenario.
16-
17-
For the complete project, refer to the [DropDownList in Razor Pages example](https://github.com/telerik/ui-for-aspnet-core-examples/blob/master/Telerik.Examples.RazorPages/Telerik.Examples.RazorPages/Pages/DropDownList/DropDownListCrudOps.cshtml).
18-
15+
## Getting Started
1916
In order to set up the Razor DropDownList component bindings, you need to configure the `Read` method of its `DataSource` instance. The URL in this method should refer the name of the method in the PageModel. In this method, you can also pass additional parameters, such as filter string and antiforgery token (see `dataFunction`).
2017

21-
```tab-HtmlHelper(csthml)
22-
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
23-
@Html.AntiForgeryToken()
24-
25-
@(Html.Kendo().DropDownList()
26-
.Name("products")
27-
.DataTextField("ShipName")
28-
.DataValueField("ShipCity")
29-
.HtmlAttributes(new { style = "width:300px;" })
30-
.AutoBind(false)
31-
.Filter(FilterType.Contains)
32-
.DataSource(ds => ds
33-
.Custom()
34-
.Transport(transport => transport
35-
.Read(read => read
36-
.Url("/DropDownList/DropDownListCrudOps?handler=Read").Data("dataFunction")
37-
))
38-
.ServerFiltering(true)
18+
```tab-HtmlHelper(csthml)
19+
20+
@(Html.Kendo().DropDownList()
21+
.Name("products")
22+
.DataTextField("ShipName")
23+
.DataValueField("ShipCity")
24+
.HtmlAttributes(new { style = "width:300px;" })
25+
.AutoBind(false)
26+
.Filter(FilterType.Contains)
27+
.DataSource(ds => ds
28+
.Custom()
29+
.Transport(transport => transport
30+
.Read(read => read
31+
.Url("/DropDownList/DropDownListCrudOps?handler=Read").Data("dataFunction")
32+
))
33+
.ServerFiltering(true)
3934
)
40-
)
41-
```
35+
)
36+
```
4237
{% if site.core %}
43-
```TagHelper
44-
45-
<kendo-dropdownlist name="products"
46-
datatextfield="ShipName"
47-
datavaluefield="ShipCity"
48-
auto-bind="false"
49-
filter="FilterType.Contains">
50-
<datasource server-filtering="true">
51-
<transport>
52-
<read url="@Url("/DropDownList/DropDownListCrudOps?handler=Read")" data="dataFunction" />
53-
</transport>
54-
</datasource>
55-
</kendo-dropdownlist>
56-
```
38+
```TagHelper
39+
40+
<kendo-dropdownlist name="products"
41+
datatextfield="ShipName"
42+
datavaluefield="ShipCity"
43+
auto-bind="false"
44+
filter="FilterType.Contains">
45+
<datasource server-filtering="true">
46+
<transport>
47+
<read url="@Url("/DropDownList/DropDownListCrudOps?handler=Read")" data="dataFunction" />
48+
</transport>
49+
</datasource>
50+
</kendo-dropdownlist>
51+
```
5752
{% endif %}
58-
```script
59-
<script>
60-
function dataFunction() {
61-
var value = $("#products").getKendoDropDownList().filterInput.val();
62-
return {
63-
__RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken,
64-
filterValue: value
65-
};
66-
}
67-
</script>
68-
```
69-
```tab-PageModel(cshtml.cs)
70-
public JsonResult OnGetRead(string filterValue)
53+
54+
1. Add an `AntiForgeryToken` at the top of the page.
55+
56+
```
57+
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
58+
@Html.AntiForgeryToken()
59+
```
60+
61+
1. Send the `AntiForgeryToken` with the [Read, Create, Update, Destroy] request.
62+
63+
```
64+
<script>
65+
function forgeryToken() {
66+
return kendo.antiForgeryTokens();
67+
}
68+
</script>
69+
```
70+
71+
Additional parameters can also be supplied.
72+
73+
```
74+
<script>
75+
function dataFunction() {
76+
var value = $("#products").getKendoDropDownList().filterInput.val();
77+
return {
78+
__RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken,
79+
filterValue: value
80+
};
81+
}
82+
</script>
83+
```
84+
85+
1. Within the `cshtml.cs` file, add a handler method for the Read operation that returns the dataset.
86+
87+
```tab-PageModel(cshtml.cs)
88+
public JsonResult OnGetRead(string filterValue)
7189
{
7290
if (filterValue != null)
7391
{
@@ -77,10 +95,13 @@ In order to set up the Razor DropDownList component bindings, you need to config
7795
}
7896
return new JsonResult(orders);
7997
}
80-
```
98+
```
8199
82100
## See Also
101+
* [Using Telerik UI for ASP.NET Core in Razor Pages](https://docs.telerik.com/aspnet-core/getting-started/razor-pages#using-telerik-ui-for-aspnet-core-in-razor-pages)
102+
* [Client-Side API of the DropDownList](https://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist)
103+
* [Server-Side HtmlHelper API of the DropDownList](/api/dropdownlist)
104+
* [Server-Side TagHelper API of the DropDownList](/api/taghelpers/dropdownlist)
105+
* [Knowledge Base Section](/knowledge-base)
83106
84-
* [Razor Pages Support]({% slug razor_pages_integration_aspnetmvc6_aspnetmvc %})
85-
* [DataBinding Overview]({% slug htmlhelpers_dropdownlist_databinding_aspnetcore %})
86107

0 commit comments

Comments
 (0)