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

Razor Page

This article describes how to configure the Telerik UI ContextMenu HtmlHelper for ASP.NET Core in a RazorPage scenario.

The example below demonstrates how to pass antiforgery token when an item from the ContextMenu is selected. 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()

    <div id="target">Right click here</div>

    @(Html.Kendo().ContextMenu()
        .Name("RequestMenu")
        .Target("#target")
        .Orientation(ContextMenuOrientation.Vertical)
        .Items(items =>
        {
            items.Add()
                .Text("Edit");

            items.Add()
                 .Text("Cancel");
        })
        .Events(e =>
        {
            e.Select("onSelect");

        })
    )

    <script>
        function onSelect(e) {
            if ($(e.item).text() == "Edit") {
                $.ajax({
                    url: "/ContextMenu/ContextMenuIndex?handler=Custom",
                    type: "POST",
                    contentType: "application/json",
                    headers: {
                        RequestVerificationToken: $('input:hidden[name="__RequestVerificationToken"]').val()
                    }
                });
            }        
        }
    </script>

    public void OnPostCustom()
        {
            ....
        }

See Also

In this article
Not finding the help you need? Improve this article