View components are new to ASP.NET Core—they didn't exist in ASP.NET pre-Core. You can think of them as replacements for partial views (which are still around) and the RenderAction method for returning child actions (which is no longer available). No more being tied to controllers; they are reusable because they can be loaded from external assemblies (that is, not the assembly of the web app) and they are better suited than partial views to render complex HTML. In the following sections, we will understand what view components are, how they work, and where we use them, as well as compare them to partial views.
Discovering view components
View components can be discovered in one of the following ways:
- By inheriting from the ViewComponent class
- By adding a [ViewComponent] attribute
- By adding the ViewComponent suffix to a class
You will most likely inherit the components...