Controller.ViewData Controller.ViewData Controller.ViewData Property


Gets or sets ViewDataDictionary used by ViewResult and ViewBag.

public Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData { get; set; }
member this.ViewData : Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary with get, set
Public Property ViewData As ViewDataDictionary

Property Value


By default, this property is initialized when IControllerActivator activates controllers.

This property can be accessed after the controller has been activated, for example, in a controller action or by overriding OnActionExecuting(ActionExecutingContext).

This property can be also accessed from within a unit test where it is initialized with EmptyModelMetadataProvider.

Applies to