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

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

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

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

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

            .DataSource(ds => ds
                .Read(r => r
            .Model(model => model.Children("Products")))

        function dataFunction() {     
            return kendo.antiForgeryTokens();
    <kendo-menu name="Menu" datatextfield="Name">
                <hierarchical-model children="Products"></hierarchical-model>
                <read url="/Menu/MenuRemoteData?handler=Read" data="dataFunction" />

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

    public JsonResult OnGetRead()
        //categories is the DBContext
        var result = categories.ToList().Select((category) =>
                Name = category.CategoryName,
                Products = category.Products
                    .Where((product) => product.CategoryID == category.CategoryID)
                    .Select((product) => new { Name = product.ProductName })
        return new JsonResult(result);

See Also

In this article