ASP. net mvc receives data from the view form POST in the controller, asp. netmvc

Source: Internet
Author: User
Tags form post asp net

ASP. net mvc receives data from the view form POST in the controller, asp. netmvc

Method 1: Request. Form

[HttpPost]
Public ActionResult Test ()
{
String id = Request. Form ["id"];

Return View ();
}

Method 2: map to FormCollection

[HttpPost]
Public ActionResult Test (FormCollection form)
{
String id = form ["id"];

Return View ();
}

Method 3: map to the Controller Parameters

[HttpPost]
Public ActionResult Test (string id)
{
// Id is the value of the Control name id obtained from the View form POST.

Return View ();
}

Method 4: map to the view Data Object

[HttpPost]
Public ActionResult Test (TModel model)
{
String id = model. id;

Return View ();
}

Method 5: Call the UpdateModel Method

[HttpPost]
Public ActionResult Test ()
{
TModel model;
UpdateModel <TModel> (model );

Return View ();
}

The values in the preceding five methods can be obtained. method 1 and method 2 are essentially the same, and method 4 and Method 5 are essentially the same, which method is used depends on the actual situation? We recommend that you use method 1 or method 3 if you want to obtain one or more specified values. If you want to obtain all values of the entire form, you can use the four-way method.

 Sync posting on my personal website: http://www.zuowenjun.cn/post/2014/10/22/63.html


Asp net mvc briefly describes how to read form data from the Controller.

Slave controller ?? You should transfer data from the view to the Controller .... request in the corresponding action in the background after the form is defined. form ["key"] to obtain the foreground value. there are many methods to transmit data from the background to the foreground)
2 viewdata [key] = value assignment
Call the model or <% = viewdata Value %> directly at the front-end.

How does the MVC View display List data transmitted from the Controller?

Foreach. You can create a new view and select a strong Object List View.

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.