Roadmap › ASP.NET Core MVC (and Razor Pages) › Module: Razor Views
Lessons in this course (15)

10. Partial views vs view components

Intermediate★ Must knowLesson 10 of 15
Partial viewView component
LogicNone (just markup with a model you pass)Has its own C# class with InvokeAsync — can call services
DataParent must supply the modelFetches its own data
UseReusable markup fragments (product card)Widgets: shopping cart summary, menu, recent posts
Invoke<partial name="_Card" model="x" />@await Component.InvokeAsync("Cart") or <vc:cart></vc:cart>
csharp
public class CartViewComponent(ICartService cart) : ViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync() => View(await cart.GetSummaryAsync(UserClaimsPrincipal));
}
// View: Views/Shared/Components/Cart/Default.cshtml

Child actions (@Html.Action) from MVC 5 no longer exist — view components replace them.