New to Telerik UI for ASP.NET Core? Download free 30-day trial

DropDownTree in Razor Pages

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).

You can seamlessly integrate the Telerik UI DropDownTree for ASP.NET Core in Razor Pages applications.

This article describes how to configure the DropDownTree component in a Razor Pages scenario.

For the complete project, refer to the DropDownTree in Razor Pages example.

In order to set up the ComboBox 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).

    @inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf

        .HtmlAttributes(new { style = "width: 100%" })
        .Checkboxes(checkboxes => checkboxes
        .DataSource(dataSource => dataSource
            .Transport(t => t
                .Read(r => r.Url(Url.Page("DropDownTreeIndex", "DropDownTreeRead")).Data("forgeryToken")))


        function forgeryToken() {
            return kendo.antiForgeryTokens();
    @inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf

    <kendo-dropdowntree datatextfield="Name" datavaluefield="id" name="dropdowntree" auto-width="true" style="width: 100%" auto-close="false">
                <hierarchical-model id="id"></hierarchical-model>
                <read url="@Url.Page("DropDownTreeIndex", "DropDownTreeRead")" data="forgeryToken" />
        <checkboxes check-children="true" enabled="true" />

        function forgeryToken() {
            return kendo.antiForgeryTokens();

        public JsonResult OnGetDropDownTreeRead(int? id)
            var data = dbContext.Where(x => id.HasValue ? x.ParentID == id : x.ParentID == null)
                .Select(item => new {
                    id = item.ID,
                    Name = item.Name,
                    hasChildren = item.HasChildren

            return new JsonResult(data);

See Also

In this article