0
votes

I have a form containing this code:

<form asp-page="TodoItem" asp-page-handler="Delete" method="post" id="myItem">

When I submit this form in my browser, a POST fires to https://localhost:44311/TodoItem?handler=Delete according to the network tab in my browser's F12 DevTools. So far so good.

But what happens in my Razor Pages project, is that on my TodoItempage, the OnPost is being run, instead of the Delete method which I wanted to run.

How can I debug this? I have the loglevel for Microsoft.AspNetCore.Routing already at Trace, it's only showing the URL in the logs, not the query string in the URL.

Also it seems I can replace the handler name with anything, so TodoItem?handler=Foobarzy also runs the OnPost, which fails completely silently - Visual Studio doesn't tell me that I'm specifying a non-existent handler using IntelliSense, the logs (in the console) don't tell me that a browser has made a strange request. Is this normal?

1

1 Answers

2
votes

According to https://www.learnrazorpages.com/razor-pages/handler-methods, your method should be named as OnPost<Action>Async. The value passed to the page-handler attribute is the name of the handler method without the OnPost prefix or Async suffix. Is it true? Could you provide handlers code ?