0

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
Rockstart
  • 2,337
  • 5
  • 30
  • 59

2 Answers2

0

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.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194
0

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.