Although it is essential to know how ASP. NET MVC programs receive information from client HTTP, there is some ambiguity about HTTP request flow and data transfer mechanisms, just a little bit today.
Take a look at the client code:
<formAction= "Default"Method= "POST" >User name:<inputtype= "text"name= "UserName" /> <inputtype= "Submit"value= "Submit" /></form>the user name you entered is: @ViewBag. UserName
Take a look at the server-side code:
public class testcontroller:controller{ [HttpGet]
public
ActionResult Default () {
return
View (); } [HttpPost]
public actionresult Default (
String
ABC) {viewbag.username = Request[
"
username
"
];
or
Viewbag.username = httpcontext.request["UserName"];
return
View (); }}
It is possible to use request["XXX" in the controller directly to receive the form items because the current controller inherits the request property of type Httprequestbase from the Controler,controler class. Since TestController inherits from the controller class here, it also has a request property of type httprequestbase inside it. This request property stores information about the client for the current HTTP request (such as the form information above).
Here the Request property is the Httprequestbase type, and when we need to hand over the task receiving the client value to a class instance other than the current controller object, you can pass the request property of the current controller object as an argument to another class instance.
Also, notice that there is a HttpContext attribute of type httpcontextbase in the controller definition.
The value that the receiving client sent over the HTTP request (Httprequestbase/httprequest, Httpcontextbase/httpconext, HttpContext.Current)