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

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

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

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

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

    @(Html.Kendo().Dialog()
        .Name("dialog")
        .Title("Data Update")
        .Content("<p>Would you like to confirm updating the data?<p>")
        .Width(400)
        .Modal(false)
        .Actions(actions =>
        {
            actions.Add().Text("Cancel");
            actions.Add().Text("Send data").Primary(true).Action("onSendData");
        })
    )   

    <script>
        function onSendData() {
            $.ajax({
                url: "/Dialog/DialogIndex",
                type: "POST",               
                headers: {
                    RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken
                },
                dataType: "json"
            });
        }
    </script>
    <kendo-dialog name="dialog" title="Data Update" width="400" modal="false" >
        <actions>            
            <action text="Cancel">
            </action>
            <action text="Send data" primary="true" action="onSendData">
            </action>
        </actions>
        <content>
            <p>Would you like to confirm updating the data?</p>
        </content>
    </kendo-dialog>

    <script>
        function onSendData() {
            $.ajax({
                url: "/Dialog/DialogIndex",
                type: "POST",               
                headers: {
                    RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken
                },
                dataType: "json"
            });
        }

    public void OnPost()
        {
            ....
        }

See Also

In this article