liveBook · Manning

View component

A view component is a reusable user-interface unit that encapsulates presentation logic for rendering a portion of a page or response.

How 2 Manning books explain it

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

Related concepts

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.