Free Web Development Online Tutorials, Learn to Code
Learn Asp.net MVC C#, Asp.net MVC Tutorial for Beginners, Model View Controller

Action Verbs in Asp.net MVC

What is ActionVerbs 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

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.

ActionVerbs in Asp.net MVC

ActionVerbs When to Use
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.

Comment
Name
Email
Website
Subscribe
 
ActionVerbs in Asp.net MVC