Home > DeveloperSection > Forums > [HttpPost/HttpGet] for Action in MVC
Sachin Singh
Sachin Singh

Total Post:26

Posted on    March-09-2016 3:48 AM

 ASP.Net C#  ASP.Net  ASP.NET MVC  Http  Https  Http Post  Http Request 

 1 Reply(s)
 893  View(s)
Rate this:
Hi Everyone,

i am using MVC with  C#. I want to know what is practical use of  [HttpPost/HttpGet] in MVC .

Can anyone give me example when we used ?

thank you.

Anupam Mishra

Total Post:135

Posted on    March-09-2016 4:02 AM

Hi Sachin,

If you are working with MVC then one controller are given by MVC when we create a New Project i.e. Account Controller. In Account Controller, we have a Login action which provides the user with a login screen, then receives the user name and password back after the user submits the form:


We see in login action [HttpGet] is the first action and [HttpPost] and the second action, MVC clearly knows which action is which. When a user views a page, that's a GET request when a user submits a form, that's usually a POST request . HttpGet and HttpPost  just restrict the action to the applicable request type.


We can also combine both request in an one action using below syntax:

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

Modified On Mar-09-2016 04:03:08 AM

Don't want to miss updates? Please click the below button!

Follow MindStick