SQL Server Technology Consulting SQL Server SSIS Snowflake Product Engineering Business Intelligence Solutions Custom Software Development Software Testing QA Microsoft Office Enterprise Software Development Java Web Development Predictive Analytics AI Development Tableau Consulting IoT App Development ML Services Gaming App Cyber Security Laravel Development Ruby on Rails PWA Xamarin App Dynamics 365 Business Central Power BI Consulting Dynamics 365 CRM Customer Insights Customer Service Finance & Operations Dynamics NAV Project Operation Sales Node.js Development NopCommerce OpenAI Development Power Apps Dynamics Consulting Power Platform AR/VR Development Big Data DevOps Consulting Custom Web Development AI/ML Company WooCommerce Full Stack Web Dev Blockchain App

ActionVerbs: HttpGet, HttpPost, HttpPut

ActionVerbs: HttpGet, HttpPost, HttpPut

The ActionVerbs selector is to handle different type of Http requests. The MVC framework includes HttpGet, HttpPost, HttpPut, HttpDelete, HttpOptions, and HttpPatch action verbs. You can apply one or more action verbs to an action method to handle different HTTP requests. If you don't apply any action verbs to an action method, then it will handle HttpGet request by default.

The following table lists the usage of HTTP methods:

 

 

 

The following example shows how to handle different types of HTTP requests in the Controller using ActionVerbs:

 

 

 

 

 

 

public class StudentController : Controller

{

    public ActionResult Index() // handles GET requests by default

    {

        return View();

    }

 

    [HttpPost]

    public ActionResult PostAction() // handles POST requests by default

    {

        return View("Index");

    }

 

    [HttpPut]

    public ActionResult PutAction() // handles PUT requests by default

    {

        return View("Index");

    }

 

    [HttpDelete]

    public ActionResult DeleteAction() // handles DELETE requests by default

    {

        return View("Index");

    }

 

    [HttpHead]

    public ActionResult HeadAction() // handles HEAD requests by default

    {

        return View("Index");

    }

       

    [HttpOptions]

    public ActionResult OptionsAction() // handles OPTION requests by default

    {

        return View("Index");

    }

       

    [HttpPatch]

    public ActionResult PatchAction() // handles PATCH requests by default

    {

        return View("Index");

    }

}

 

You can also apply multiple action verbs using the AcceptVerbs attribute, as shown below.

 

 

[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]

public ActionResult GetAndPostAction()

{

    return RedirectToAction("Index");

}

Previous Next

ssssssStart Your Data Journey Today With MSAInfotech

Take the first step towards data-led growth by partnering with MSA Infotech. Whether you seek tailored solutions or expert consultation, we are here to help you harness the power of data for your business. Contact us today and let’s embark on this transformative data adventure together. Get a free consultation today!

check

We utilize data to transform ourselves, our clients, and the world.

check

Partnership with leading data platforms and certified talents

FAQ Robot

How Can We Help?

Captcha
Back to Top
MSA Infotech ×