View components in ASP.NET Core

ViewComponent was introduced in ASP.NET Core MVC. It can do everything that a partial view can and can do even more. ViewComponents are completely self-contained objects that consistently render html from a razor view. 

It is quite similar to the partial view in terms of reusability and reduce code repetition.

View components do not use model binding. But, it works only with the data provided when we called it. Like Partial View, View components does not depend on controllers. It has its own class to implement the logic to develop the component’s model and razor markup view page. The most important thing is that View Components can utilize dependency injection, which makes them very much powerful and testable.

A View Components has the following features –

- View Components supports SOC (Separation-Of-Concerns)

- It can have its own business logic as well as parameter

- It is always invoked from the Layout Page

- It always renders chunk rather than a whole process.


View Components is actually behaving like a web part which contains both business logic and UI design to create a web part package which can be reused in the multiple parts of the web application.

View Components also involves processing by both a view component class and a View. The View Component class must be derived from the ViewComponent class.