Microsoft.AspNetCore.Mvc

Contains types for building web applications with ASP.NET Core MVC.

Controllers

Controller

public abstract class Controller : ControllerBase

Represents a base class for controllers in an MVC application.

namespace: Microsoft.AspNetCore.Mvc type: class

ControllerBase

public abstract class ControllerBase

A base class that provides essential MVC controller functionality.

namespace: Microsoft.AspNetCore.Mvc type: class

ApiControllerAttribute

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] public sealed class ApiControllerAttribute : Attribute

Indicates that a controller is an API controller, enabling API-specific behaviors.

namespace: Microsoft.AspNetCore.Mvc type: class

Action Methods

Action

public abstract class Action : Attribute

Base class for action method attributes.

namespace: Microsoft.AspNetCore.Mvc type: class

HttpGetAttribute

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)] public sealed class HttpGetAttribute : MethodAttribute

Constrains requests to HTTP GET.

namespace: Microsoft.AspNetCore.Mvc type: class

HttpPostAttribute

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)] public sealed class HttpPostAttribute : MethodAttribute

Constrains requests to HTTP POST.

namespace: Microsoft.AspNetCore.Mvc type: class

ActionNameAttribute

[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] public sealed class ActionNameAttribute : Attribute

Specifies the name of an action method.

namespace: Microsoft.AspNetCore.Mvc type: class

Filters

IActionFilter

public interface IActionFilter

Interface for action filters.

  • void OnActionExecuting(ActionExecutingContext context);
  • void OnActionExecuted(ActionExecutedContext context);
namespace: Microsoft.AspNetCore.Mvc.Filters type: interface

IResultFilter

public interface IResultFilter

Interface for result filters.

  • void OnResultExecuting(ResultExecutingContext context);
  • void OnResultExecuted(ResultExecutedContext context);
namespace: Microsoft.AspNetCore.Mvc.Filters type: interface

AuthorizeAttribute

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] public class AuthorizeAttribute : Attribute, IAuthorizationFilter

Specifies that an action or controller requires authorization.

namespace: Microsoft.AspNetCore.Authorization type: class

Model Binding

IModelBinder

public interface IModelBinder

Interface for model binders.

  • Task BindModelAsync(ModelBindingContext bindingContext);
namespace: Microsoft.AspNetCore.Mvc.ModelBinding type: interface

BindAttribute

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false, AllowMultiple = false)] public abstract class BindAttribute : Attribute

Specifies that a parameter or property should be bound.

namespace: Microsoft.AspNetCore.Mvc type: class

View Data

ViewDataAttribute

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)] public class ViewDataAttribute : Attribute

Provides a mechanism to pass data to views.

namespace: Microsoft.AspNetCore.Mvc type: class

ViewBag

public dynamic ViewBag { get; }

A dynamic property bag that allows you to set arbitrary properties and access them from the view.

namespace: Microsoft.AspNetCore.Mvc type: property

Routing

RouteAttribute

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] public class RouteAttribute : Attribute

Specifies a route template for the associated action or controller.

namespace: Microsoft.AspNetCore.Mvc type: class

IRouter

public interface IRouter

Interface for route handlers.

  • Task RouteAsync(RouteContext context);
namespace: Microsoft.AspNetCore.Routing type: interface

Result Types

IActionResult

public interface IActionResult

Represents an action result.

  • Task ExecuteResultAsync(ActionContext context);
namespace: Microsoft.AspNetCore.Mvc type: interface

OkResult

public sealed class OkResult : StatusCodeResult

An action result that returns an empty OK (200) response.

namespace: Microsoft.AspNetCore.Mvc type: class

NotFoundResult

public sealed class NotFoundResult : StatusCodeResult

An action result that returns a Not Found (404) response.

namespace: Microsoft.AspNetCore.Mvc type: class

JsonResult

public class JsonResult : ActionResult<object>

An action result that returns a JSON response.

namespace: Microsoft.AspNetCore.Mvc type: class