In MVC, the Controller is used to respond to requests for ASP.NET MVC websites. Each browser request will be mapped to a specific Controller instance. The Controller may perform the following processing for the request: return a specific view to the browser or respond to the request Redirect to another Controller.
Controller is essentially a class, all derived from Controller (System.Web.Mvc.Controller base class).
The public method on the Controller is called ControllerAction. ControllerAction cannot be overloaded and cannot be a static method.
The return value of ControllerAction is called ActionResult, which is the content information returned by Controller in response to browser request. At present, its types mainly include:
☆ViewResult |
HTML and markup (commonly used) |
EmptyResult |
any result |
RedirectResult |
redirect to new URL |
JsonResult |
JavaScript Object Notation Results in Ajax Requests |
JavaScriptResult |
JavaScript script |
ContentResult |
plain text results |
FileContentResult |
Downloadable files (with binary content) |
FilePathResult |
Path to downloadable file |
FileStreamResult |
Downloadable files (using file streams) |
Usually, ActionResult is not directly returned in the program, but the method of the Controller base class is called to return,
View() |
View, return ViewResult |
Redirect() |
Redirect, return RedirectResult |
RedirectToAction() |
Returns RedirectToRouteResult |
RedirectToRoute() |
Returns RedirectToRouteResult |
Json() |
return JsonResult |
JavaScriptResult() |
return JavaScriptResult |
Content() |
return ContentResult |
File() |
Returns FileContentResult, FilePathResult or FileStreamResult |