HttpGet HttpPost, httpget and httppost for ActionResult

Source: Internet
Author: User

HttpGet HttpPost, httpget and httppost for ActionResult

GET is generally used to obtain and query data.

When the browser sends an http get request, it will find the corresponding Action specified by HttpGet.

POST is generally used to update data.

When there is no limit on the Action, Any HTTP verb sent by the browser will automatically select the corresponding Action.

When receiving form information, you can create two actions with the same name. One applies the HttpGet attribute to display form information, and the other uses the HttpPost qualifier to receive form values.


[HttpPost] What is the role of ASPNET ??

Hmm ...... In mvc, [httppost] is used to add this method, and [httpGet] is used to jump to a view or call a method, httpGet indicates the call when the method is loaded for the first time, httpPost indicates the second, third, and N times.
For example:
[HttpGet]
Public ActionResult Add ()
{
Return View ();
}

[HttpPost]
Public ActionResult Add (Model_Add model)
{
Return View ();
}
This Add method. HttpGet is the first request for this method, and then returns a view. Then, when HttpPost initiates the second request in the Add view, it is the following Add method, submit data, parameters, and so on.

In VS2012 mvc4, what is [HttpPost? And why rewrite these two identical methods?

To complete user login, first obtain a View using the Get method, and then use the Post method to accept the submitted Form for user login verification.
Therefore, there are two Login actions in the Controller, but the two are different. The difference lies in GET and POST.
Get action is relatively simple, as follows:
//
// GET:/Account/Login/
Public ActionResult Login ()
{
Return View ();
}
The POST action is more complex. You need to call the corresponding functions from the Model, as shown below:
//
// POST:/Account/Login
[AcceptVerbs (HttpVerbs. Post)]
Public ActionResult Login (FormCollection collection)
{
Try
{
String email = collection ["email"];
String password = collection ["password"];
Password = System. Web. Security. FormsAuthentication. HashPasswordForStoringInConfigFile (password, "md5 ");
......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.