Are all MVC Controller actions ,decorated with [HttpGet] by default internally?
Or
Should I explicitly add the attribute to all controller actions to avoid post on the same?
Are all MVC Controller actions ,decorated with [HttpGet] by default internally?
Or
Should I explicitly add the attribute to all controller actions to avoid post on the same?
In ASP.NET MVC if you do not specify the method, it will accept all http verbs. Usually is a used by get
.
To specify a http verb, you should decorate the action method with the appropriate attribute, for sample, for a POST
method, you should use HttpPost
as the code bellow.
[HttpPost]
public ActionResult Save(ProductViewModel product)
{
return View();
}
There also verbs like:
HttpPut
for PUT
HttpDelete
for DELETE
HttpPatch
for
PATCH
Take a look at Request Method to know more about.
The default verb is Get for the controllers. I would recommended that you place a verb for each Controller Action ( [HttpGet], [HttpPut], [HttpPost], [HttpDelete] ), to help with reading the code without guessing what the Actions is doing.