Adding the Cart Total to All of the Pages
Understand how to persist and display the shopping cart total on every page by integrating it into the MainLayout component. Learn to update the UI using Blazor's event handling and StateHasChanged method while managing resources by properly unsubscribing events.
We'll cover the following...
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:
- Return to Visual Studio.
- Open the
Shared\MainLayout.razorpage. - Add the following
@usingdirective:
- Add the following
@injectdirective: