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

PanelBar 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 PanelBar for ASP.NET Core in Razor Pages applications.

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

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

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


    @inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
    @Html.AntiForgeryToken()

    @(Html.Kendo().PanelBar()
        .Name("panelbar")
        .DataTextField("Name")
        .DataSource(dataSource => dataSource
            .Read(read => read
                .Url("/PanelBar/PanelBarRemoteData?handler=Read")
            )
        )
    )   

    @inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
    @Html.AntiForgeryToken()

    <kendo-panelbar name="panelbar" datatextfield="Name">
        <hierarchical-datasource>
            <transport>
                <read url="/PanelBar/PanelBarRemoteData?handler=Read" />
            </transport>
        </hierarchical-datasource>
    </kendo-panelbar>

    public JsonResult OnGetRead(int? id)
    {       
        //employees is the DBContext
        var result = employees.ToList()
            .Where(v => id.HasValue ? v.ReportsTo == id : v.ReportsTo == null)
            .Select((employee) =>
                new
                {
                    id = employee.EmployeeID,
                    Name = employee.FirstName + " " + employee.LastName,
                    hasChildren = employees.Any(o => o.ReportsTo == employee.EmployeeID)
                }
        );
        return new JsonResult(result);
    }

See Also

In this article