In MVC, a controller responds to a request to an ASP. NET MVC site, and each browser request is mapped to a specific controller instance. The controller may do the following for a request: return a specific view to the browser or redirect the request to another controller.
The controller is essentially a class that derives from the controller (System.Web.Mvc.Controller base class).
A public method on a controller 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 that the controller returns in response to a browser request. At present, its types mainly include:
☆viewresult |
HTML and Tags (common) |
Emptyresult |
Any results |
Redirectresult |
Redirect to new URL |
Jsonresult |
JavaScript object representation results in AJAX requests |
Javascriptresult |
JavaScript scripts |
Contentresult |
Plain Text Results |
Filecontentresult |
Downloadable files (using binary content) |
Filepathresult |
The path to the downloadable file |
Filestreamresult |
Downloadable files (using file streams) |
In general, the program does not directly return ActionResult, but instead calls the Controller base class method to return,
View () |
View, return Viewresult |
Redirect () |
Redirect, return Redirectresult |
Redirecttoaction () |
Back to Redirecttorouteresult |
Redirecttoroute () |
Back to Redirecttorouteresult |
Json () |
Back to Jsonresult |
Javascriptresult () |
Back to Javascriptresult |
Content () |
Back to Contentresult |
File () |
Returns Filecontentresult, Filepathresult, or Filestreamresult |
ASP. NET MVC Learning Note-2. Controller