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 ");
......