Controller (Controllers)
In the context of the MVC schema pattern, the controller responds to the user's input (for example, the user taps the "Save" button) and coordinates the model, view, and (often) the data access layer. In an ASP. NET MVC program, the controller is the class that contains the method that is called when the routing framework processes the request.
The
controller action
Controller class is nothing special, unlike anything else. NET classes are almost indistinguishable. In fact, the methods in the control shun class (called the operations in the controller) do the main work during the processing request. Often hear the controller and controller operation of the word, in this book is also called, in fact, the MVC model does not distinguish between the two. However, the ASP. NET MVC framework focuses on the controller operation because it contains the actual logic code that handles the request.
For example, the Homecontronller class contains three operations: Index,about and contact. However, assuming that the default route pattern is {controller}/{action}/{id}, When a requested URL is/home/about, the routing framework determines that the request is handled by the about method in the HomeController class. The ASP. NET MVC framework then creates an instance of Homcontroller and executes the About () method.
In this example, the About () method is very simple: it passes the data to the view through the ViewBag property, and then asp.net the MVC framework to display a view named (about) by calling the view () method , this operation returns the result of an operation of type Viewresult.
Operation result
It is important to note that the controller's job is to tell the ASP. What to do next, not how. This communication process is accomplished by using +actionresult+s, which is the operation provided by the Controller. For example, when the controller decides how to display the view, it tells the ASP. Net-Viewresult to show the view by returning it instead of rendering the view itself. This loosely coupled design is also the direct embodiment of the principle of "separation of concerns" in operation.
Although the operations of each controller are returned to ActionResult, most of the time you do not need to do it manually. Instead, you only need to use the help methods provided by the System.Web.MVc.Controller base class, for example:
Content (): Returns the Contentresult of the file type, such as "Hello, world!".
File (): Returns the contents of the type of Fileresult, such as PDF.
Httpnotfound () returns the Httpnotfoundresult that contains the 404HTTP status code.
JavaScript (): Return Javascriptresult
ASP. NET MVC4 Learning System III (Controller controllers)