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

Razor Page

This article describes how to configure a Remote DataSource of a Telerik Menu in a RazorPage scenario.

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). See the implementation details in the example below, and for the full project with RazorPages examples, visit our GitHub repository.


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

    @(Html.Kendo().Menu()
            .Name("Menu")
            .DataTextField("Name")
            .DataSource(ds => ds
                .Read(r => r
                    .Url("/Menu/MenuRemoteData?handler=Read").Data("dataFunction")
                )
            .Model(model => model.Children("Products")))
    )

    <script>  
        function dataFunction() {     
            return kendo.antiForgeryTokens();
        }
    </script>
```tab-TagHelper(cshtml)
    <kendo-menu name="Menu" datatextfield="Name">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model children="Products"></hierarchical-model>
            </schema>
            <transport>
                <read url="/Menu/MenuRemoteData?handler=Read" data="dataFunction" />
            </transport>
        </hierarchical-datasource>
    </kendo-menu>

    <script>  
        function dataFunction() {     
            return kendo.antiForgeryTokens();
        }
    </script>
```

    public JsonResult OnGetRead()
    {
        //categories is the DBContext
        var result = categories.ToList().Select((category) =>
            new
            {
                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