Home > Software design >  Why this HTTPGET method in Controller can work?
Why this HTTPGET method in Controller can work?

Time:11-16

I'm learning ASP.NET CORE 6 with MS official website below: enter image description here

So the question is why I ask a request with POST method, but it still can lead to a GET action method?

Yes you are right. In that case, either you have to define as method="get" or you can define and controller and action together. Like this

<form asp-action="index" asp-controller="YourController">

Or

 <form asp-action="index" method="get">

Note: In official document they used enter image description here

Note: Using method attribute method="get" is more suitable to resolve your issue other than in browser compiler autometically generate post by default.

CodePudding user response:

According to HTML specification default value for form.method attributge is 'get'. See https://www.w3.org/TR/html401/interact/forms.html#edef-FORM and https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/method. That's why it works with GET action, as if you specified <form asp-action="index" method="get">

  • Related