ASP.NET MVC ActionResult and Its Subtypes (ViewResult…)
From the book "Beginning ASP.NET MVC 4":
The ActionResult class is the base class for all the specific implementations of action results. The following classes derive from the ActionResult class and can be used as an action method’s return type:
• ViewResult: Used to return a view to render HTML in the browser. This is the most common ActionResult.
• PartialViewResult: Similar to ViewResult, it returns a partial view.
• ContentResult: Used to return any type of content. By default, it is used to return plain text, but the actual content type can be explicitly defined (e.g. text/xml).
• EmptyResult: This is the equivalent of a void method—it is by definition an action result object, but it does nothing.
• FileResult: Used to return binary content (e.g., if you want to download a file).
• HttpUnauthorizedResult: You can return an HttpUnauthorizedResult object when the request tries to access restricted content that, for example, is not available to anonymous users. The browser is then redirected to the login page.
• JavaScriptResult: Used to return JavaScript code.
• JsonResult: Used to return an object in JavaScript Object Notation (JSON) format.
• RedirectResult: Used to perform an HTTP redirect to another URL. You can define it as a temporary (code 302) or permanent (code 301) HTTP redirect.
• RedirectToRouteResult: used to perform an HTTP redirect, but to a specific route rather than a URL.
From Stackoverflow:
ActionResult is an abstract class that can have several subtypes.
__
ViewResult - Renders a specified view to the response stream
PartialViewResult - Renders a specified partial view to the response stream
EmptyResult - An empty response is returned
RedirectResult - Performs an HTTP redirection to a specifed URL
RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
JsonResult - Serializes a given ViewData object to JSON format
JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
ContentResult - Writes content to the response stream without requiring a view
FileContentResult - Returns a file to the client
FileStreamResult - Returns a file to the client, which is provided by a Stream
FilePathResult - Returns a file to the client
__
However, both of above missed HttpStautsCodeResult, which is also a subtype of ActionResult:
_HttpStautsCodeResult: Provides a way to return an action result with a specific HTTP response status code and description. ( from Microsoft )
_
public ActionResult Index()
{
//unsupported
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad Request");
}