I'm learning ASP.NET CORE 6 with MS official website below:
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
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">