...

/

Adding the Cart Total to All of the Pages

Adding the Cart Total to All of the Pages

Learn how to add a component to all pages using the MainLayout component.

We'll cover the following...

To view the cart total on all of the pages, we need to add the cart total to a component that is used on all of the pages. Since the MainLayout component is used by all of the pages, we will add the cart total to it. We do this as follows:

  1. Return to Visual Studio.
  2. Open the Shared\MainLayout.razor page.
  3. Add the following @using directive:
Press + to interact
@using ShoppingCart.Services
  1. Add the following @inject directive:
Press + to interact
@inject ICartService cartService
...