When would you use OnPut or OnDelete in Razor Pages?

1.2k views Asked by At

I saw this question asked on twitter. What are the real world uses of OnPut and OnDelete handlers in Razor Pages applications in ASP.NET Core? Since HTML forms do not support the HTTP verbs PUT and DELETE (they only support GET and POST), are these handlers meant for page-based requests, or APIs?

1

There are 1 answers

0
ssmith On

The OnPut and OnDelete handlers will be less commonly used but might be called by JavaScript on a page when you want to keep all of the page's server side operations logically together, as opposed to creating a separate API controller. The product team originally only supported OnGet and OnPost handlers for Razor Pages, but eventually chose to add the others because they saw no reason to block them.