View component
A view component is a reusable user-interface unit that encapsulates presentation logic for rendering a portion of a page 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
- Uses view components to render independent, logic-rich regions without burdening the main Razor page.
- How deep it goes
- Explains component creation, dependency injection, view location, parameter passing, and invocation with a worked recipe example.
- Examples
- Uses a current-user recipe component alongside shopping carts, dynamic menus, and login widgets as examples.
- What you can do after
- Build view components from scratch by deriving from ViewComponent, implementing InvokeAsync(), and invoking them from Razor views.
Read how ASP.NET Core in Action, 3e explains view component →
Also covered in
What to know first
- Razor PagesRazor Pages is an ASP.NET Core page-focused programming model in which independently addressable pages combine Razor markup with request-handling logic.
- subtemplateA subtemplate is a reusable template fragment that can be rendered independently or included within another template to produce part of an output.
- Tag HelpersTag Helpers are ASP.NET Core components that process HTML-like elements during Razor view or page rendering.
- unit testA unit test is an automated test that checks whether a relatively small unit of software behaves as expected, typically in isolation from external dependencies.
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.
- contextuses · Context is the relevant information, state, or circumstances surrounding an input, decision, or activity that influence its interpretation or behavior.
- Invoke methoduses · Invoke is the conventional ASP.NET Core middleware method that processes an HTTP request and can receive dependencies through its parameters.
- InvokeAsyncused by · InvokeAsync is an API method for invoking an operation asynchronously and obtaining or scheduling its result.
Questions about view component
What is view component?
A view component is a reusable user-interface unit that encapsulates presentation logic for rendering a portion of a page or response.
Which Manning books explain view component?
Pro ASP.NET Core 7, Tenth Edition and ASP.NET Core in Action, 3e.
What should I know before learning view component?
Manning books that teach view component usually introduce Razor Pages, subtemplate, Tag Helpers and unit test first.
What is the difference between view component and subtemplate?
A view component is a reusable user-interface unit that encapsulates presentation logic for rendering a portion of a page or response. A subtemplate is a reusable template fragment that can be rendered independently or included within another template to produce part of an output.
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.

