Export (0) Print
Expand All

Controller Class

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

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

public abstract class Controller : ControllerBase, 
	IActionFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter

A controller class name must end with "Controller". For example, a Product controller could 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 (C# Programming Guide).

  • 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 property of the ContentResult object is set to the invariant string representation of the returned object.

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

Community Additions

Show:
© 2014 Microsoft