This is a migrated thread and some comments may be shown as answers.

Razorpages wrong handler is called

3 Answers 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BitShift
Top achievements
Rank 1
Veteran
BitShift asked on 03 Jan 2020, 10:51 PM

I have a razorpage with a grid and these methods on the DataSource.

 

                        .Update(u => u.Url("/Audit?handler=Update").Data("forgeryToken"))
                        .Create(c => c.Url("/Audit?handler=Create").Data("forgeryToken"))
                        .Destroy(d => d.Url("/Audit?handler=Destroy").Data("forgeryToken"))

 

For some reason when I edit a row, then hit update, I get a 400 error as the request is being made for Audit?handler=Create instead of the Update handler?

What can I check?

My Update handler
        public JsonResult OnPostUpdate([DataSourceRequest] DataSourceRequest request, ViewLineItemModel localOrder)
        {

            // get updated order from parameter
            // save updates to db

           //....
            // test
            JsonResult r = new JsonResult(localOrder);
            return r;
        }

3 Answers, 1 is accepted

Sort by
0
BitShift
Top achievements
Rank 1
Veteran
answered on 03 Jan 2020, 10:57 PM

Even If I hit the Delete button, the same error mentions the Create handler being called

                        columns.Command(column =>
                        {
                            column.Edit();
                            column.Destroy();                           
                        }).Width(125);

http 400, bad request
http://localhost:60101/Audit?handler=Create

0
Accepted
Al
Top achievements
Rank 1
answered on 04 Jan 2020, 07:01 PM
I've just completed the first leg an extremely painful journey into this world and this is one error I haven't seen although I've seen many. My best advise is to get a minimal working model and compare to your problem project especially using F12 on Chrome to dissect the elements and look for clues (and of course check the browser console for errors).
0
BitShift
Top achievements
Rank 1
Veteran
answered on 06 Jan 2020, 01:11 PM

Yes, AI that is what I was doing and it finally dawned on me that it was the inclusion of the forgerytoken was causing malformed requests.  Once I did that things started working

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

 

Tags
Grid
Asked by
BitShift
Top achievements
Rank 1
Veteran
Answers by
BitShift
Top achievements
Rank 1
Veteran
Al
Top achievements
Rank 1
Share this question
or