Controller Class
Provides methods that respond to HTTP requests that are made to an ASP.NET MVC Web site.
System.Web.Mvc.ControllerBase
System.Web.Mvc.Controller
System.Web.Mvc.AsyncController
Namespace: System.Web.Mvc
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
The Controller type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ActionInvoker | Gets the action invoker for the controller. |
![]() | AsyncManager | Provides asynchronous operations. |
![]() | Binders | Gets or sets the binder. |
![]() | ControllerContext | Gets or sets the controller context. (Inherited from ControllerBase.) |
![]() | DisableAsyncSupport | Disable asynchronous support to provide backward compatibility. |
![]() | HttpContext | Gets HTTP-specific information about an individual HTTP request. |
![]() | ModelState | Gets the model state dictionary object that contains the state of the model and of model-binding validation. |
![]() | Profile | Gets the HTTP context profile. |
![]() | Request | Gets the HttpRequestBase object for the current HTTP request. |
![]() | Response | Gets the HttpResponseBase object for the current HTTP response. |
![]() | RouteData | Gets the route data for the current request. |
![]() | Server | Gets the HttpServerUtilityBase object that provides methods that are used during Web request processing. |
![]() | Session | Gets the HttpSessionStateBase object for the current HTTP request. |
![]() | TempData | Gets or sets the dictionary for temporary data. (Inherited from ControllerBase.) |
![]() | TempDataProvider | Gets the temporary-data provider object that is used to store data for the next request. |
![]() | Url | Gets the URL helper object that is used to generate URLs by using routing. |
![]() | User | Gets the user security information for the current HTTP request. |
![]() | ValidateRequest | Gets or sets a value that indicates whether request validation is enabled for this request. (Inherited from ControllerBase.) |
![]() | ValueProvider | Gets or sets the value provider for the controller. (Inherited from ControllerBase.) |
![]() | ViewBag | Gets the dynamic view data dictionary. (Inherited from ControllerBase.) |
![]() | ViewData | Gets or sets the dictionary for view data. (Inherited from ControllerBase.) |
![]() | ViewEngineCollection | Gets the view engine collection. |
| Name | Description | |
|---|---|---|
![]() | BeginExecute | Begins execution of the specified request context |
![]() | BeginExecuteCore | Begins to invoke the action in the current controller context. |
![]() | Content(String) | Creates a content result object by using a string. |
![]() | Content(String, String) | Creates a content result object by using a string and the content type. |
![]() | Content(String, String, Encoding) | Creates a content result object by using a string, the content type, and content encoding. |
![]() | CreateActionInvoker | Creates an action invoker. |
![]() | CreateTempDataProvider | Creates a temporary data provider. |
![]() | Dispose() | Releases all resources that are used by the current instance of the Controller class. |
![]() | Dispose(Boolean) | Releases unmanaged resources and optionally releases managed resources. |
![]() | EndExecute | Ends the invocation of the action in the current controller context. |
![]() | EndExecuteCore | Ends the execute core. |
![]() | Equals | (Inherited from Object.) |
![]() | Execute | Executes the specified request context. (Inherited from ControllerBase.) |
![]() | ExecuteCore | Invokes the action in the current controller context. (Overrides ControllerBase.ExecuteCore().) |
![]() | File(Byte[], String) | Creates a FileContentResult object by using the file contents and file type. |
![]() | File(Stream, String) | Creates a FileStreamResult object by using the Stream object and content type. |
![]() | File(String, String) | Creates a FilePathResult object by using the file name and the content type. |
![]() | File(Byte[], String, String) | Creates a FileContentResult object by using the file contents, content type, and the destination file name. |
![]() | File(Stream, String, String) | Creates a FileStreamResult object using the Stream object, the content type, and the target file name. |
![]() | File(String, String, String) | Creates a FilePathResult object by using the file name, the content type, and the file download name. |
![]() | Finalize | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() | HandleUnknownAction | Called when a request matches this controller, but no method with the specified action name is found in the controller. |
![]() | HttpNotFound() | Returns an instance of the HttpNotFoundResult class. |
![]() | HttpNotFound(String) | Returns an instance of the HttpNotFoundResult class. |
![]() | Initialize | Initializes data that might not be available when the constructor is called. (Overrides ControllerBase.Initialize(RequestContext).) |
![]() | JavaScript | Creates a JavaScriptResult object. |
![]() | Json(Object) | Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON). |
![]() | Json(Object, String) | Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format. |
![]() | Json(Object, JsonRequestBehavior) | Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified JSON request behavior. |
![]() | Json(Object, String, Encoding) | Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format. |
![]() | Json(Object, String, JsonRequestBehavior) | Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified content type and JSON request behavior. |
![]() | Json(Object, String, Encoding, JsonRequestBehavior) | Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the content type, content encoding, and the JSON request behavior. |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | OnActionExecuted | Called after the action method is invoked. |
![]() | OnActionExecuting | Called before the action method is invoked. |
![]() | OnAuthorization | Called when authorization occurs. |
![]() | OnException | Called when an unhandled exception occurs in the action. |
![]() | OnResultExecuted | Called after the action result that is returned by an action method is executed. |
![]() | OnResultExecuting | Called before the action result that is returned by an action method is executed. |
![]() | PartialView() | Creates a PartialViewResult object that renders a partial view. |
![]() | PartialView(Object) | Creates a PartialViewResult object that renders a partial view, by using the specified model. |
![]() | PartialView(String) | Creates a PartialViewResult object that renders a partial view, by using the specified view name. |
![]() | PartialView(String, Object) | Creates a PartialViewResult object that renders a partial view, by using the specified view name and model. |
![]() | Redirect | Creates a RedirectResult object that redirects to the specified URL. |
![]() | RedirectPermanent | Returns an instance of the RedirectResult class with the Permanent property set to true. |
![]() | RedirectToAction(String) | Redirects to the specified action using the action name. |
![]() | RedirectToAction(String, Object) | Redirects to the specified action using the action name and route values. |
![]() | RedirectToAction(String, String) | Redirects to the specified action using the action name and controller name. |
![]() | RedirectToAction(String, RouteValueDictionary) | Redirects to the specified action using the action name and route dictionary. |
![]() | RedirectToAction(String, String, Object) | Redirects to the specified action using the action name, controller name, and route values. |
![]() | RedirectToAction(String, String, RouteValueDictionary) | Redirects to the specified action using the action name, controller name, and route dictionary. |
![]() | RedirectToActionPermanent(String) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name. |
![]() | RedirectToActionPermanent(String, Object) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, and route values. |
![]() | RedirectToActionPermanent(String, String) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, and controller name. |
![]() | RedirectToActionPermanent(String, RouteValueDictionary) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, and route values. |
![]() | RedirectToActionPermanent(String, String, Object) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, controller name, and route values. |
![]() | RedirectToActionPermanent(String, String, RouteValueDictionary) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, controller name, and route values. |
![]() | RedirectToRoute(Object) | Redirects to the specified route using the specified route values. |
![]() | RedirectToRoute(String) | Redirects to the specified route using the route name. |
![]() | RedirectToRoute(RouteValueDictionary) | Redirects to the specified route using the route dictionary. |
![]() | RedirectToRoute(String, Object) | Redirects to the specified route using the route name and route values. |
![]() | RedirectToRoute(String, RouteValueDictionary) | Redirects to the specified route using the route name and route dictionary. |
![]() | RedirectToRoutePermanent(Object) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route values. |
![]() | RedirectToRoutePermanent(String) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route name. |
![]() | RedirectToRoutePermanent(RouteValueDictionary) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route values. |
![]() | RedirectToRoutePermanent(String, Object) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route name and route values. |
![]() | RedirectToRoutePermanent(String, RouteValueDictionary) | Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route name and route values. |
![]() | ToString | (Inherited from Object.) |
![]() | TryUpdateModel(TModel)(TModel) | Updates the specified model instance using values from the controller's current value provider. |
![]() | TryUpdateModel(TModel)(TModel, String) | Updates the specified model instance using values from the controller's current value provider and a prefix. |
![]() | TryUpdateModel(TModel)(TModel, String[]) | Updates the specified model instance using values from the controller's current value provider and included properties. |
![]() | TryUpdateModel(TModel)(TModel, IValueProvider) | Updates the specified model instance using values from the value provider. |
![]() | TryUpdateModel(TModel)(TModel, String, String[]) | Updates the specified model instance using values from the controller's current value provider, a prefix, and included properties. |
![]() | TryUpdateModel(TModel)(TModel, String, IValueProvider) | Updates the specified model instance using values from the value provider and a prefix. |
![]() | TryUpdateModel(TModel)(TModel, String[], IValueProvider) | Updates the specified model instance using values from the value provider and a list of properties to include. |
![]() | TryUpdateModel(TModel)(TModel, String, String[], String[]) | Updates the specified model instance using values from the controller's current value provider, a prefix, a list of properties to exclude, and a list of properties to include. |
![]() | TryUpdateModel(TModel)(TModel, String, String[], IValueProvider) | Updates the specified model instance using values from the value provider, a prefix, and included properties. |
![]() | TryUpdateModel(TModel)(TModel, String, String[], String[], IValueProvider) | Updates the specified model instance using values from the value provider, a prefix, a list of properties to exclude , and a list of properties to include. |
![]() | TryValidateModel(Object) | Validates the specified model instance. |
![]() | TryValidateModel(Object, String) | Validates the specified model instance using an HTML prefix. |
![]() | UpdateModel(TModel)(TModel) | Updates the specified model instance using values from the controller's current value provider. |
![]() | UpdateModel(TModel)(TModel, String) | Updates the specified model instance using values from the controller's current value provider and a prefix. |
![]() | UpdateModel(TModel)(TModel, String[]) | Updates the specified model instance using values from the controller object's current value provider. |
![]() | UpdateModel(TModel)(TModel, IValueProvider) | Updates the specified model instance using values from the value provider. |
![]() | UpdateModel(TModel)(TModel, String, String[]) | Updates the specified model instance using values from the controller's current value provider, a prefix, and included properties. |
![]() | UpdateModel(TModel)(TModel, String, IValueProvider) | Updates the specified model instance using values from the value provider and a prefix. |
![]() | UpdateModel(TModel)(TModel, String[], IValueProvider) | Updates the specified model instance using values from the value provider, a prefix, and a list of properties to include. |
![]() | UpdateModel(TModel)(TModel, String, String[], String[]) | Updates the specified model instance using values from the controller's current value provider, a prefix, a list of properties to exclude, and a list of properties to include. |
![]() | UpdateModel(TModel)(TModel, String, String[], IValueProvider) | Updates the specified model instance using values from the value provider, a prefix, and a list of properties to include. |
![]() | UpdateModel(TModel)(TModel, String, String[], String[], IValueProvider) | Updates the specified model instance using values from the value provider, a prefix, a list of properties to exclude, and a list of properties to include. |
![]() | ValidateModel(Object) | Validates the specified model instance. |
![]() | ValidateModel(Object, String) | Validates the specified model instance using an HTML prefix. |
![]() | View() | Creates a ViewResult object that renders a view to the response. |
![]() | View(Object) | Creates a ViewResult object by using the model that renders a view to the response. |
![]() | View(String) | Creates a ViewResult object by using the view name that renders a view. |
![]() | View(IView) | Creates a ViewResult object that renders the specified IView object. |
![]() | View(String, Object) | Creates a ViewResult object by using the view name and model that renders a view to the response. |
![]() | View(String, String) | Creates a ViewResult object using the view name and master-page name that renders a view to the response. |
![]() | View(IView, Object) | Creates a ViewResult object that renders the specified IView object. |
![]() | View(String, String, Object) | Creates a ViewResult object using the view name, master-page name, and model that renders a view. |
| Name | Description | |
|---|---|---|
![]() ![]() | IActionFilter.OnActionExecuted | This API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnActionExecuted method. |
![]() ![]() | IActionFilter.OnActionExecuting | This API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnActionExecuting method. |
![]() ![]() | IAsyncController.BeginExecute | Initializes a new instance of the IAsyncController.BeginExecute(RequestContext, AsyncCallback, Object) class. |
![]() ![]() | IAsyncController.EndExecute | Ends the execute task. |
![]() ![]() | IAuthorizationFilter.OnAuthorization | This API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnAuthorization method. |
![]() ![]() | IController.Execute | Executes the specified request context. (Inherited from ControllerBase.) |
![]() ![]() | IExceptionFilter.OnException | This API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnException method. |
![]() ![]() | IResultFilter.OnResultExecuted | This API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnResultExecuted method. |
![]() ![]() | IResultFilter.OnResultExecuting | This API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnResultExecuting method. |
A controller class name must end with "Controller". For example, a Product controller can be named ProductController but not Product or ProductCtrl.
The content last updated March 14, 2012
Controller action methods respond to requests that are sent to the controller. Controller action methods have the following restrictions:
Action methods must be public.
Action methods cannot be static.
Action methods cannot have unbounded generic type parameters. An unbounded generic type parameter has an empty parameter list. An unbounded generic type is also known as an open generic type. For information about unbounded generic type parameters, see the section "Unbounded Type Parameters" in Constraints on Type Parameters.
Action methods cannot be overloaded based on parameters. Action methods can be overloaded when they are disambiguated with attributes such as NonActionAttribute or AcceptVerbsAttribute.
The following table lists the types that a controller action method can return and the scenarios for which the types are returned.
Return type | Control action return |
|---|---|
void or null | The ControllerActionInvoker object returns an EmptyResult object. |
The ControllerActionInvoker object calls the ExecuteResult method on the result. | |
Object (excluding ActionResult) | The result is passed to a CreateActionResult, which creates a new ContentResult object. The Content method of the ContentResult object is set to the invariant string representation of the returned object. |
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)