Usually we have an ASP. when a Controller is created in the net mvc project, the default return type of the Index () method is ActionResult. by viewing the UML diagram, ActionResult is actually an abstract class, therefore, the type actually returned is the subclass of this abstract class.
ØActionResultAnd its subclassUMLFigure
The UML diagram of ActionResult and its subclass is as follows:
Because the image size is large, it may seem small and inconvenient in the browser. You can click here to download the large image and open it in a professional image browser.
Download big chart
ØActionResultComparison table of its subclass
|
ActionResultSubclass name |
Description |
|
ViewResult |
HTML page content |
|
EmptyResult |
Blank Page Content |
|
RedirectResult |
Locate another URL |
|
JsonResult |
JSON results that can be applied to AJAX programs |
|
JavaScriptResult |
Represents a JavaScript Object |
|
ContentResult |
Indicates a text content |
|
FileContentResult |
Indicates a file that can be downloaded and binary. |
|
FilePathResult |
Indicates a file that can be downloaded and specified path |
|
FileStreamResult |
Indicates a downloadable and streaming file. |
By writing the code, we can easily see the following code:
Public ActionResult Index ()
{
Return View ();
}
Some people may wonder why the returned value is View since I define ActionResult?
In fact, this View type is the subclass of ActionResult ViewResult. For methods and returned objects in the Controller, see the following table:
|
ControllerMethod in |
Returned object |
|
View |
ViewResult |
|
Redirect |
RedirectResult |
|
RedirectToAction |
RedirectToActionResult |
|
RedirectToRoute |
RedirectToRouteResult |
|
Json |
JsonResult |
|
JavaScriptResult |
JavaScriptResult |
|
Content |
ContentResult |
|
File |
FileContentResult, FilePathResult, and FileStreamResult |