Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
ASP.NET MVC 1.0
Controller Class
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
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)
Visual Basic (Declaration)
Public MustInherit Class Controller _
    Inherits ControllerBase _
    Implements IActionFilter, IAuthorizationFilter, IDisposable, IExceptionFilter,  _
    IResultFilter
Visual Basic (Usage)
Dim instance As Controller
C#
public abstract class Controller : ControllerBase, 
    IActionFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter
Visual C++
public ref class Controller abstract : public 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.

System..::.Object
  System..::.MarshalByRefObject
    System.Web.Mvc..::.ControllerBase
      System.Web.Mvc..::.Controller
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker