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.