ViewComponent Class

Summary

A base class for view components.

Syntax

public abstract class ViewComponent

GitHub

View on GitHub

class Microsoft.AspNet.Mvc.ViewComponent

Properties

Context()

Gets the @!:HttpContext-.

Return type:HttpContext
public HttpContext Context { get; }
ModelState()

Gets the [Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary]().

Return type:Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary
public ModelStateDictionary ModelState { get; }
Request()

Gets the @!:HttpRequest-.

Return type:HttpRequest
public HttpRequest Request { get; }
RouteData()

Gets the [Microsoft.AspNet.Mvc.ViewComponent.RouteData](Microsoft.AspNet.Mvc.ViewComponent.yml) for the current request.

Return type:RouteData
public RouteData RouteData { get; }
Url()

Gets or sets the [Microsoft.AspNet.Mvc.IUrlHelper]().

Return type:Microsoft.AspNet.Mvc.IUrlHelper
public IUrlHelper Url { get; set; }
User()

Gets the [System.Security.Principal.IPrincipal]() for the current user.

Return type:System.Security.Principal.IPrincipal
public IPrincipal User { get; }
ViewBag()

Gets the view bag.

Return type:dynamic
public ViewBag { get; }
ViewComponentContext()
Return type:Microsoft.AspNet.Mvc.ViewComponentContext
public ViewComponentContext ViewComponentContext { get; set; }
ViewContext()

Gets the [Microsoft.AspNet.Mvc.ViewComponent.ViewContext](Microsoft.AspNet.Mvc.ViewComponent.yml).

Return type:Microsoft.AspNet.Mvc.ViewContext
public ViewContext ViewContext { get; }
ViewData()

Gets the [Microsoft.AspNet.Mvc.ViewDataDictionary](Microsoft.AspNet.Mvc.ViewDataDictionary.yml).

Return type:Microsoft.AspNet.Mvc.ViewDataDictionary
public ViewDataDictionary ViewData { get; }
ViewEngine()

Gets or sets the [Microsoft.AspNet.Mvc.Rendering.ICompositeViewEngine](Microsoft.AspNet.Mvc.Rendering.ICompositeViewEngine.yml).

Return type:Microsoft.AspNet.Mvc.Rendering.ICompositeViewEngine
public ICompositeViewEngine ViewEngine { get; set; }

Methods

Content(System.String)

Returns a result which will render HTML encoded text.

Arguments:
  • content (System.String) – The content, will be HTML encoded before output.
Return type:

Microsoft.AspNet.Mvc.ContentViewComponentResult

Returns:

A [Microsoft.AspNet.Mvc.ContentViewComponentResult](Microsoft.AspNet.Mvc.ContentViewComponentResult.yml).

public ContentViewComponentResult Content(string content)
Json(System.Object)

Returns a result which will render JSON text.

Arguments:
  • value (System.Object) – The value to output in JSON text.
Return type:

Microsoft.AspNet.Mvc.JsonViewComponentResult

Returns:

A [Microsoft.AspNet.Mvc.JsonViewComponentResult](Microsoft.AspNet.Mvc.JsonViewComponentResult.yml).

public JsonViewComponentResult Json(object value)
Json(System.Object, JsonSerializerSettings)

Returns a result which will render JSON text.

Arguments:
  • value (System.Object) – The value to output in JSON text.
  • serializerSettings (JsonSerializerSettings) – The @!:JsonSerializerSettings- to be used by the formatter.
Return type:

Microsoft.AspNet.Mvc.JsonViewComponentResult

Returns:

A [Microsoft.AspNet.Mvc.JsonViewComponentResult](Microsoft.AspNet.Mvc.JsonViewComponentResult.yml).

public JsonViewComponentResult Json(object value, JsonSerializerSettings serializerSettings)
Microsoft.AspNet.Mvc.ViewComponent.View()

Returns a result which will render the partial view with name <c>”Default”</c>.

Return type:Microsoft.AspNet.Mvc.ViewViewComponentResult
Returns:A [Microsoft.AspNet.Mvc.ViewViewComponentResult](Microsoft.AspNet.Mvc.ViewViewComponentResult.yml).
public ViewViewComponentResult View()
View(System.String)

Returns a result which will render the partial view with name <paramref name=”viewName” />.

Arguments:
  • viewName (System.String) – The name of the partial view to render.
Return type:

Microsoft.AspNet.Mvc.ViewViewComponentResult

Returns:

A [Microsoft.AspNet.Mvc.ViewViewComponentResult](Microsoft.AspNet.Mvc.ViewViewComponentResult.yml).

public ViewViewComponentResult View(string viewName)
Microsoft.AspNet.Mvc.ViewComponent.View<TModel>(System.String, TModel)

Returns a result which will render the partial view with name <paramref name=”viewName” />.

Arguments:
  • viewName (System.String) – The name of the partial view to render.
  • model (TModel) – The model object for the view.
Return type:

Microsoft.AspNet.Mvc.ViewViewComponentResult

Returns:

A [Microsoft.AspNet.Mvc.ViewViewComponentResult](Microsoft.AspNet.Mvc.ViewViewComponentResult.yml).

public ViewViewComponentResult View<TModel>(string viewName, TModel model)
Microsoft.AspNet.Mvc.ViewComponent.View<TModel>(TModel)

Returns a result which will render the partial view with name <c>”Default”</c>.

Arguments:
  • model (TModel) – The model object for the view.
Return type:

Microsoft.AspNet.Mvc.ViewViewComponentResult

Returns:

A [Microsoft.AspNet.Mvc.ViewViewComponentResult](Microsoft.AspNet.Mvc.ViewViewComponentResult.yml).

public ViewViewComponentResult View<TModel>(TModel model)