Controller Class¶
A base class for an MVC controller with view support.
- Namespace
Microsoft.AspNetCore.Mvc
- Assemblies
- Microsoft.AspNetCore.Mvc.ViewFeatures
Syntax¶
public abstract class Controller : ControllerBase, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable
-
class
Microsoft.AspNetCore.Mvc.
Controller
Methods¶
-
Dispose
()¶ public void Dispose()
-
Dispose
(System.Boolean) Releases all resources currently used by this
Microsoft.AspNetCore.Mvc.Controller
instance.Arguments: disposing (System.Boolean) – <code>true</code> if this method is being invoked by the Microsoft.AspNetCore.Mvc.Controller.Dispose
method, otherwise <code>false</code>.protected virtual void Dispose(bool disposing)
-
Json
(System.Object)¶ Creates a
Microsoft.AspNetCore.Mvc.JsonResult
object that serializes the specified <em>data</em> object to JSON.Arguments: data (System.Object) – The object to serialize. Return type: Microsoft.AspNetCore.Mvc.JsonResult Returns: The created Microsoft.AspNetCore.Mvc.JsonResult
that serializes the specified <em>data</em> to JSON format for the response.public virtual JsonResult Json(object data)
-
Json
(System.Object, Newtonsoft.Json.JsonSerializerSettings) Creates a
Microsoft.AspNetCore.Mvc.JsonResult
object that serializes the specified <em>data</em> object to JSON.Arguments: - data (System.Object) – The object to serialize.
- serializerSettings (Newtonsoft.Json.JsonSerializerSettings) – The
Newtonsoft.Json.JsonSerializerSettings
to be used by the formatter.
Return type: Returns: The created
Microsoft.AspNetCore.Mvc.JsonResult
that serializes the specified <em>data</em> as JSON format for the response.public virtual JsonResult Json(object data, JsonSerializerSettings serializerSettings)
-
OnActionExecuted
(Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext)¶ Called after the action method is invoked.
Arguments: context (Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext) – The action executed context. public virtual void OnActionExecuted(ActionExecutedContext context)
-
OnActionExecuting
(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext)¶ Called before the action method is invoked.
Arguments: context (Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext) – The action executing context. public virtual void OnActionExecuting(ActionExecutingContext context)
-
OnActionExecutionAsync
(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext, Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate)¶ Called before the action method is invoked.
Arguments: - context (Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext) – The action executing context.
- next (Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate) – The
Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate
to execute. Invoke this delegate in the body ofMicrosoft.AspNetCore.Mvc.Controller.OnActionExecutionAsync(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext,Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate)
to continue execution of the action.
Return type: System.Threading.Tasks.Task
Returns: A
System.Threading.Tasks.Task
instance.public virtual Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
-
PartialView
()¶ Creates a
Microsoft.AspNetCore.Mvc.PartialViewResult
object that renders a partial view to the response.Return type: Microsoft.AspNetCore.Mvc.PartialViewResult Returns: The created Microsoft.AspNetCore.Mvc.PartialViewResult
object for the response.public virtual PartialViewResult PartialView()
-
PartialView
(System.Object) Creates a
Microsoft.AspNetCore.Mvc.PartialViewResult
object by specifying a <em>model</em> to be rendered by the partial view.Arguments: model (System.Object) – The model that is rendered by the partial view. Return type: Microsoft.AspNetCore.Mvc.PartialViewResult Returns: The created Microsoft.AspNetCore.Mvc.PartialViewResult
object for the response.public virtual PartialViewResult PartialView(object model)
-
PartialView
(System.String) Creates a
Microsoft.AspNetCore.Mvc.PartialViewResult
object by specifying a <em>viewName</em>.Arguments: viewName (System.String) – The name of the view that is rendered to the response. Return type: Microsoft.AspNetCore.Mvc.PartialViewResult Returns: The created Microsoft.AspNetCore.Mvc.PartialViewResult
object for the response.public virtual PartialViewResult PartialView(string viewName)
-
PartialView
(System.String, System.Object) Creates a
Microsoft.AspNetCore.Mvc.PartialViewResult
object by specifying a <em>viewName</em> and the <em>model</em> to be rendered by the partial view.Arguments: - viewName (System.String) – The name of the partial view that is rendered to the response.
- model (System.Object) – The model that is rendered by the partial view.
Return type: Returns: The created
Microsoft.AspNetCore.Mvc.PartialViewResult
object for the response.public virtual PartialViewResult PartialView(string viewName, object model)
-
View
()¶ Creates a
Microsoft.AspNetCore.Mvc.ViewResult
object that renders a view to the response.Return type: Microsoft.AspNetCore.Mvc.ViewResult Returns: The created Microsoft.AspNetCore.Mvc.ViewResult
object for the response.public virtual ViewResult View()
-
View
(System.Object) Creates a
Microsoft.AspNetCore.Mvc.ViewResult
object by specifying a <em>model</em> to be rendered by the view.Arguments: model (System.Object) – The model that is rendered by the view. Return type: Microsoft.AspNetCore.Mvc.ViewResult Returns: The created Microsoft.AspNetCore.Mvc.ViewResult
object for the response.public virtual ViewResult View(object model)
-
View
(System.String) Creates a
Microsoft.AspNetCore.Mvc.ViewResult
object by specifying a <em>viewName</em>.Arguments: viewName (System.String) – The name of the view that is rendered to the response. Return type: Microsoft.AspNetCore.Mvc.ViewResult Returns: The created Microsoft.AspNetCore.Mvc.ViewResult
object for the response.public virtual ViewResult View(string viewName)
-
View
(System.String, System.Object) Creates a
Microsoft.AspNetCore.Mvc.ViewResult
object by specifying a <em>viewName</em> and the <em>model</em> to be rendered by the view.Arguments: - viewName (System.String) – The name of the view that is rendered to the response.
- model (System.Object) – The model that is rendered by the view.
Return type: Returns: The created
Microsoft.AspNetCore.Mvc.ViewResult
object for the response.public virtual ViewResult View(string viewName, object model)
-
ViewComponent
(System.String)¶ Creates a
Microsoft.AspNetCore.Mvc.ViewComponentResult
by specifying the name of a view component to render.Arguments: componentName (System.String) – The view component name. Can be a view component Microsoft.AspNetCore.Mvc.ViewComponents.ViewComponentDescriptor.ShortName
orMicrosoft.AspNetCore.Mvc.ViewComponents.ViewComponentDescriptor.FullName
.Return type: Microsoft.AspNetCore.Mvc.ViewComponentResult Returns: The created Microsoft.AspNetCore.Mvc.ViewComponentResult
object for the response.public virtual ViewComponentResult ViewComponent(string componentName)
-
ViewComponent
(System.String, System.Object) Creates a
Microsoft.AspNetCore.Mvc.ViewComponentResult
by specifying the name of a view component to render.Arguments: - componentName (System.String) – The view component name. Can be a view component
Microsoft.AspNetCore.Mvc.ViewComponents.ViewComponentDescriptor.ShortName
orMicrosoft.AspNetCore.Mvc.ViewComponents.ViewComponentDescriptor.FullName
. - arguments (System.Object) – An
System.Object
with properties representing arguments to be passed to the invoked view component method. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the invocation arguments.
Return type: Returns: The created
Microsoft.AspNetCore.Mvc.ViewComponentResult
object for the response.public virtual ViewComponentResult ViewComponent(string componentName, object arguments)
- componentName (System.String) – The view component name. Can be a view component
-
ViewComponent
(System.Type) Creates a
Microsoft.AspNetCore.Mvc.ViewComponentResult
by specifying theSystem.Type
of a view component to render.Arguments: componentType (System.Type) – The view component System.Type
.Return type: Microsoft.AspNetCore.Mvc.ViewComponentResult Returns: The created Microsoft.AspNetCore.Mvc.ViewComponentResult
object for the response.public virtual ViewComponentResult ViewComponent(Type componentType)
-
ViewComponent
(System.Type, System.Object) Creates a
Microsoft.AspNetCore.Mvc.ViewComponentResult
by specifying theSystem.Type
of a view component to render.Arguments: - componentType (System.Type) – The view component
System.Type
. - arguments (System.Object) – An
System.Object
with properties representing arguments to be passed to the invoked view component method. Alternatively, anSystem.Collections.Generic.IDictionary`2
instance containing the invocation arguments.
Return type: Returns: The created
Microsoft.AspNetCore.Mvc.ViewComponentResult
object for the response.public virtual ViewComponentResult ViewComponent(Type componentType, object arguments)
- componentType (System.Type) – The view component
-
Properties¶
-
Microsoft.AspNetCore.Mvc.Controller.
TempData
¶ Gets or sets
Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionary
used byMicrosoft.AspNetCore.Mvc.ViewResult
.Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionary public ITempDataDictionary TempData { get; set; }
-
Microsoft.AspNetCore.Mvc.Controller.
ViewBag
¶ Gets the dynamic view bag.
Return type: System.Object public dynamic ViewBag { get; }
-
Microsoft.AspNetCore.Mvc.Controller.
ViewData
¶ Gets or sets
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
used byMicrosoft.AspNetCore.Mvc.ViewResult
andMicrosoft.AspNetCore.Mvc.Controller.ViewBag
.Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary public ViewDataDictionary ViewData { get; set; }
-