Export (0) Print
Expand All

Controller Class

Provides methods that respond to HTTP requests that are made to an ASP.NET MVC Web site.

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

public abstract class Controller extends ControllerBase implements IActionFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter

The Controller type exposes the following members.

  NameDescription
Protected methodControllerInitializes a new instance of the Controller class.
Top

  NameDescription
Public propertyActionInvokerGets the action invoker for the controller.
Protected propertyBindersGets or sets the binder.
Public propertyControllerContextGets or sets the controller context. (Inherited from ControllerBase.)
Public propertyHttpContextGets HTTP-specific information about an individual HTTP request.
Public propertyModelStateGets the model state dictionary object that contains the state of the model and of model-binding validation.
Public propertyRequestGets the HttpRequestBase object for the current HTTP request.
Public propertyResponseGets the HttpResponseBase object for the current HTTP response.
Public propertyRouteDataGets the route data for the current request.
Public propertyServerGets the HttpServerUtilityBase object that provides methods that are used during Web request processing.
Public propertySessionGets the HttpSessionStateBase object for the current HTTP request.
Public propertyTempDataGets or sets the dictionary for temporary data. (Inherited from ControllerBase.)
Public propertyTempDataProviderGets the temporary-data provider object that is used to store data for the next request.
Public propertyUrlGets the URL helper object that is used to generate URLs by using routing.
Public propertyUserGets the user security information for the current HTTP request.
Public propertyValidateRequestGets or sets a value that indicates whether request validation is enabled for this request. (Inherited from ControllerBase.)
Public propertyValueProviderGets or sets the value provider for the controller. (Inherited from ControllerBase.)
Public propertyViewBagGets the dynamic view data dictionary. (Inherited from ControllerBase.)
Public propertyViewDataGets or sets the dictionary for view data. (Inherited from ControllerBase.)
Top

  NameDescription
Protected methodContent(String)Creates a content result object by using a string.
Protected methodContent(String, String)Creates a content result object by using a string and the content type.
Protected methodContent(String, String, Encoding)Creates a content result object by using a string, the content type, and content encoding.
Protected methodCreateActionInvokerCreates an action invoker.
Protected methodCreateTempDataProviderCreates a temporary data provider.
Public methodDispose()Releases all resources that are used by the current instance of the Controller class.
Protected methodDispose(Boolean)Releases unmanaged resources and optionally releases managed resources.
Public methodEquals (Inherited from Object.)
Protected methodExecuteExecutes the specified request context. (Inherited from ControllerBase.)
Protected methodExecuteCoreInvokes the action in the current controller context. (Overrides ControllerBase.ExecuteCore().)
Protected methodFile(Byte[], String)Creates a FileContentResult object by using the file contents and file type.
Protected methodFile(Stream, String)Creates a FileStreamResult object by using the Stream object and content type.
Protected methodFile(String, String)Creates a FilePathResult object by using the file name and the content type.
Protected methodFile(Byte[], String, String)Creates a FileContentResult object by using the file contents, content type, and the destination file name.
Protected methodFile(Stream, String, String)Creates a FileStreamResult object using the Stream object, the content type, and the target file name.
Protected methodFile(String, String, String)Creates a FilePathResult object by using the file name, the content type, and the file download name.
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodHandleUnknownActionCalled when a request matches this controller, but no method with the specified action name is found in the controller.
Protected methodHttpNotFound()Returns an instance of the HttpNotFoundResult class.
Protected methodHttpNotFound(String)Returns an instance of the HttpNotFoundResult class.
Protected methodInitializeInitializes data that might not be available when the constructor is called. (Overrides ControllerBase.Initialize(RequestContext).)
Protected methodJavaScriptCreates a JavaScriptResult object.
Protected methodJson(Object)Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON).
Protected methodJson(Object, String)Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.
Protected methodJson(Object, JsonRequestBehavior)Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified JSON request behavior.
Protected methodJson(Object, String, Encoding)Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.
Protected methodJson(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.
Protected methodJson(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.
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnActionExecutedCalled after the action method is invoked.
Protected methodOnActionExecutingCalled before the action method is invoked.
Protected methodOnAuthorizationCalled when authorization occurs.
Protected methodOnExceptionCalled when an unhandled exception occurs in the action.
Protected methodOnResultExecutedCalled after the action result that is returned by an action method is executed.
Protected methodOnResultExecutingCalled before the action result that is returned by an action method is executed.
Protected methodPartialView()Creates a PartialViewResult object that renders a partial view.
Protected methodPartialView(Object)Creates a PartialViewResult object that renders a partial view, by using the specified model.
Protected methodPartialView(String)Creates a PartialViewResult object that renders a partial view, by using the specified view name.
Protected methodPartialView(String, Object)Creates a PartialViewResult object that renders a partial view, by using the specified view name and model.
Protected methodRedirectCreates a RedirectResult object that redirects to the specified URL.
Protected methodRedirectPermanentReturns an instance of the RedirectResult class with the Permanent property set to true.
Protected methodRedirectToAction(String)Redirects to the specified action using the action name.
Protected methodRedirectToAction(String, Object)Redirects to the specified action using the action name and route values.
Protected methodRedirectToAction(String, String)Redirects to the specified action using the action name and controller name.
Protected methodRedirectToAction(String, RouteValueDictionary)Redirects to the specified action using the action name and route dictionary.
Protected methodRedirectToAction(String, String, Object)Redirects to the specified action using the action name, controller name, and route values.
Protected methodRedirectToAction(String, String, RouteValueDictionary)Redirects to the specified action using the action name, controller name, and route dictionary.
Protected methodRedirectToActionPermanent(String)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name.
Protected methodRedirectToActionPermanent(String, Object)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, and route values.
Protected methodRedirectToActionPermanent(String, String)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, and controller name.
Protected methodRedirectToActionPermanent(String, RouteValueDictionary)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified action name, and route values.
Protected methodRedirectToActionPermanent(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.
Protected methodRedirectToActionPermanent(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.
Protected methodRedirectToRoute(Object)Redirects to the specified route using the specified route values.
Protected methodRedirectToRoute(String)Redirects to the specified route using the route name.
Protected methodRedirectToRoute(RouteValueDictionary)Redirects to the specified route using the route dictionary.
Protected methodRedirectToRoute(String, Object)Redirects to the specified route using the route name and route values.
Protected methodRedirectToRoute(String, RouteValueDictionary)Redirects to the specified route using the route name and route dictionary.
Protected methodRedirectToRoutePermanent(Object)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route values.
Protected methodRedirectToRoutePermanent(String)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route name.
Protected methodRedirectToRoutePermanent(RouteValueDictionary)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route values.
Protected methodRedirectToRoutePermanent(String, Object)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route name and route values.
Protected methodRedirectToRoutePermanent(String, RouteValueDictionary)Returns an instance of the RedirectResult class with the Permanent property set to true using the specified route name and route values.
Public methodToString (Inherited from Object.)
Protected methodTryUpdateModel(TModel)(TModel)Updates the specified model instance using values from the controller's current value provider.
Protected methodTryUpdateModel(TModel)(TModel, String)Updates the specified model instance using values from the controller's current value provider and a prefix.
Protected methodTryUpdateModel(TModel)(TModel, String[])Updates the specified model instance using values from the controller's current value provider and included properties.
Protected methodTryUpdateModel(TModel)(TModel, IValueProvider)Updates the specified model instance using values from the value provider.
Protected methodTryUpdateModel(TModel)(TModel, String, String[])Updates the specified model instance using values from the controller's current value provider, a prefix, and included properties.
Protected methodTryUpdateModel(TModel)(TModel, String, IValueProvider)Updates the specified model instance using values from the value provider and a prefix.
Protected methodTryUpdateModel(TModel)(TModel, String[], IValueProvider)Updates the specified model instance using values from the value provider and a list of properties to include.
Protected methodTryUpdateModel(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.
Protected methodTryUpdateModel(TModel)(TModel, String, String[], IValueProvider)Updates the specified model instance using values from the value provider, a prefix, and included properties.
Protected methodTryUpdateModel(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.
Protected methodTryValidateModel(Object)Validates the specified model instance.
Protected methodTryValidateModel(Object, String)Validates the specified model instance using an HTML prefix.
Protected methodUpdateModel(TModel)(TModel)Updates the specified model instance using values from the controller's current value provider.
Protected methodUpdateModel(TModel)(TModel, String)Updates the specified model instance using values from the controller's current value provider and a prefix.
Protected methodUpdateModel(TModel)(TModel, String[])Updates the specified model instance using values from the controller object's current value provider.
Protected methodUpdateModel(TModel)(TModel, IValueProvider)Updates the specified model instance using values from the value provider.
Protected methodUpdateModel(TModel)(TModel, String, String[])Updates the specified model instance using values from the controller's current value provider, a prefix, and included properties.
Protected methodUpdateModel(TModel)(TModel, String, IValueProvider)Updates the specified model instance using values from the value provider and a prefix.
Protected methodUpdateModel(TModel)(TModel, String[], IValueProvider)Updates the specified model instance using values from the value provider, a prefix, and a list of properties to include.
Protected methodUpdateModel(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.
Protected methodUpdateModel(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.
Protected methodUpdateModel(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.
Protected methodValidateModel(Object)Validates the specified model instance.
Protected methodValidateModel(Object, String)Validates the specified model instance using an HTML prefix.
Protected methodView()Creates a ViewResult object that renders a view to the response.
Protected methodView(Object)Creates a ViewResult object by using the model that renders a view to the response.
Protected methodView(String)Creates a ViewResult object by using the view name that renders a view.
Protected methodView(IView)Creates a ViewResult object that renders the specified IView object.
Protected methodView(String, Object)Creates a ViewResult object by using the view name and model that renders a view to the response.
Protected methodView(String, String)Creates a ViewResult object using the view name and master-page name that renders a view to the response.
Protected methodView(IView, Object)Creates a ViewResult object that renders the specified IView object.
Protected methodView(String, String, Object)Creates a ViewResult object using the view name, master-page name, and model that renders a view.
Top

  NameDescription
Explicit interface implemetationPrivate methodIActionFilter.OnActionExecutedThis API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnActionExecuted method.
Explicit interface implemetationPrivate methodIActionFilter.OnActionExecutingThis API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnActionExecuting method.
Explicit interface implemetationPrivate methodIAuthorizationFilter.OnAuthorizationThis API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnAuthorization method.
Explicit interface implemetationPrivate methodIController.ExecuteExecutes the specified request context. (Inherited from ControllerBase.)
Explicit interface implemetationPrivate methodIExceptionFilter.OnExceptionThis API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnException method.
Explicit interface implemetationPrivate methodIResultFilter.OnResultExecutedThis API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnResultExecuted method.
Explicit interface implemetationPrivate methodIResultFilter.OnResultExecutingThis API supports the ASP.NET MVC infrastructure and is not intended to be used directly from your code. This method calls the OnResultExecuting method.
Top

A controller class name must end with "Controller". For example, a Product controller can be named ProductController but not Product or ProductCtrl.

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.

ActionResult

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.

A Visual Studio project with source code is available to accompany this topic: Download.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft