Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8330369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:06:09+00:00 2026-06-09T02:06:09+00:00

I am using MVC C#. Can somebody give an example on why one would

  • 0

I am using MVC C#.

Can somebody give an example on why one would use

[HttpPost/HttpGet] 

for an Action. How can an active have both – what is the practical use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:06:11+00:00Added an answer on June 9, 2026 at 2:06 am

    Let’s say you 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:

    public ActionResult Login() {
        return View();
    }
    
    public ActionResult Login(string userName, string password) {
        // do login stuff
        return View();
    }
    

    MVC isn’t being given clear instructions on which action is which, even though we can tell by looking at it. If you add [HttpGet] to the first action and [HttpPost] to the section action, MVC clearly knows which action is which.

    Why? See Request Methods. Long and short: When a user views a page, that’s a GET request and when a user submits a form, that’s usually a POST request. HttpGet and HttpPost just restrict the action to the applicable request type.

    [HttpGet]
    public ActionResult Login() {
        return View();
    }
    
    [HttpPost]
    public ActionResult Login(string userName, string password) {
        // do login stuff
        return View();
    }
    

    You can also combine the request method attributes if your action serves requests from multiple verbs:

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MVC with /<module>/<controller>/<action>/ have a module at example.com/module/whatever, and I need to
ASP.NET MVC can generate HTML elements using HTML Helpers, for example @Html.ActionLink() , @Html.BeginForm()
Using ASP.NET MVC can be used the view engine Razor. Razor let you use
I'm using MVC 3 and Razor. I have a page where you can create
Im using Mvc and jquery, i would like to know how can I get
How can I minimize the footprint of a website built using MVC. My application
Can we create a WEB GRID dynamically using JAVASCRIPT ? I am using MVC
I am building a web site in C# using asp.NET MVC How can I
Im using MVC-Viewmodel, EF Model first on my project. I have a foreach loop
I am using MVC 3 architecture in my project. I have a master page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.