Return failure when calling Post Handler on Razor Page

Hello.

I have a grid that has its datasource and delete methods as razor page handlers, however, when the token expires, I would like to return a message and then redirect to the login screen. I couldn't find anything about it.

Thanks


2 Replies 1 reply marked as answer

RS Rajapandiyan Settu Syncfusion Team August 18, 2022 01:45 PM UTC

Hi Rodrigo,


Thanks for contacting Syncfusion support.

Currently, we are validating the reported query with the provided details. So, we will update further details on or before Aug 22nd, 2022.


We appreciate your patience until then.


Regards,

Rajapandiyan S



RS Rajapandiyan Settu Syncfusion Team August 22, 2022 04:28 PM UTC

Hi Rodrigo,


Thanks for your patience.

You can achieve your requirement by throwing exception when token expires during the Grid actions. The actionFailure event will triggered on this exception and in that event, you can navigate to the login page.


In the below sample, we throw exception while deleting a record from Grid.


actionFailure: https://ej2.syncfusion.com/javascript/documentation/api/grid/#actionfailure


 

[index.cshtml]

@Html.AntiForgeryToken()

    <div>

        <ejs-grid id="assetgrid21" actionFailure="actionFailure" allowPaging="true" allowGrouping="true" allowsorting="true" allowFiltering="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "Search" })"  height="300" load="onLoad" >

        </ejs-grid>

 

    </div>

<script>

    function onLoad() {

        this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name=__RequestVerificationToken]").val() }];

    }

 

    function actionFailure(args){

        if(args && args.error && args.error[0] && args.error[0].error && args.error[0].error.responseText.indexOf("Token Expired")){

            alert("Token Expired");

            window.location.rel='nofollow' href = "/Login";  // navigate to another page

        }

    }

</script>

 

[index.cshtml.cs]

        public JsonResult OnPostRemove([FromBody] CRUDModel<OrdersDetails> value)

        {

            throw new Exception("Token Expired");

            ---

        }


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/razor_grid_delte_navigate_to_login-1851489708.zip


Please get back to us if you need further assistance.


Regards,

Rajapandiyan S


Marked as answer
Loader.
Up arrow icon