Action Verbs in Asp.net MVC

ActionVerbs are type of attributes, when you apply these attributes to action method that indicate what kind of Http request the action method supports

What is ActionVerbs in Asp.Net MVC?

In Asp.net MVC framework there are different ActionVerbs selectors attribute like HttpGet, HttpPost, HttpPut, HttpDelete, HttpOptions, HttpPatch.

If you do not specify any attribute on an action then it considers it a [HttpGet] request by default.

How to use ActionVerbs in Asp.net MVC

We can use action verbs like attribute [HttpGet] on top of action method like example below.

[HttpGet]
public ActionResult index()
{
    return View();
}
  • HttpGET
    this is by default, if you don't specify anything then the action will consider HttpGET, all parameters will be added in the query string with "&".
  • HttpPost
    Submit data, create a new resource, data are NOT posted through query string
  • HttpPut
    Same as Post, but normally used for updating an existing resource.
  • HttpDelete
    Delete an existing resource.
  • HttpPatch
    Used for partial update
  • HttpHead
    Same as HttpGET, except server do not return body message
ActionVerbs Example in Asp.net MVC
public class customerController : Controller                
{
    [HttpGet]
    public ActionResult index()
    {
        return View();
    }
    [HttpPost]
    public ActionResult index(customer model)
    {
        return View("index");
    }
    [HttpPost]
    public ActionResult PostCustomer()
    {
        return View("index");
    }
    [HttpDelete]
    public ActionResult DeleteCustomer()
    {
        return View("index");
    }
    [HttpPut]
    public ActionResult PutCustomer()
    {
        return View();
    }
    [HttpPatch]
    public ActionResult PatchCustomer()
    {
        return View();
    }           
    [HttpOptions] 
    public ActionResult OptionsCustomer()
    {
        return View();
    } 
                
}

Most of the time we use Get and Post in application development, Get is default, if you don’t specify anything then that's considered as HttpGet.

 
ActionVerbs in Asp.net MVC
Aspnet MVC Training
Asp.net MVC tutorials, learn model view controllers with c#, develop database driven web application using Asp.net MVC framework.
Hire .Net Developer
Free Tutorials
ASP.NET MVC Interview Questions Answers
Asp.Net MVC C# Examples | Join Asp.Net MVC Course | Asp.net Core Tutorial