View component
A view component is a reusable presentation component that encapsulates application logic and renders a portion of a user interface or response.
Pro ASP.NET Core 7, Tenth Edition
The ViewComponent base class is the ASP.NET Core MVC base class that supplies view-component behavior and access to request context.
- How it is used
- Supplies reusable navigation and cart-summary content inside layouts without making it part of each action’s view model.
- How deep it goes
- Works through class discovery, injected data, Razor rendering, parent arguments, and request context rather than framework internals.
- Examples
- Builds category navigation and a shopping-cart summary, then demonstrates an asynchronous page-size display.
- What you can do after
- Build it from scratch: inject a service, implement Invoke, render a Razor view, and embed the result in a layout.
Read how Pro ASP.NET Core 7, Tenth Edition explains view component →
ASP.NET Core in Action, 3e
ViewComponent is the ASP.NET Core base class from which custom view component classes can derive.
- How it is used
- Renders independent page sections that need both business logic and HTML without adding those responsibilities to the main Razor page.
- How deep it goes
- Shows inheritance, InvokeAsync, dependency injection, parameter passing, and view-location conventions through a custom component.
- Examples
- Uses a current-user recipe component, plus shopping carts and dynamic menus as other independent page sections.
- What you can do after
- Build it from scratch by deriving from ViewComponent, implementing InvokeAsync(), supplying a component view, and invoking it from Razor.
Read how ASP.NET Core in Action, 3e explains view component →
Related concepts
- dependency injectionuses · Dependency injection is a software design technique in which a component receives its dependencies from outside rather than creating or locating them internally.
- subtemplatecontrasts with · A subtemplate is a reusable template fragment that can be rendered independently or included within another template to produce part of an output.
- InvokeAsyncused by · InvokeAsync is an API method for invoking an operation asynchronously and obtaining or scheduling its result.
- contextuses · Context is the surrounding information, state, or circumstances that condition how an entity, event, or task is interpreted or how a system behaves.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

