This little demo is based on a Gist written by Steve Sanderson where he shows how to persist state in the browser using sessionStorage. His demo shows how to persist the counter value but I wanted to try something a bit more real-world, a very simple shopping cart, and also to use localStorage rather than sessionStorage. You can download the project here.
Install Packages
Microsoft.AspNetCore.ProtectedBrowserStorage
Microsoft.AspNetCore.Components.ProtectedBrowserStorage
Note:
- This is a .NET Core 3.1 framework will not work with .NET 5.0
- Use
Blazored.LocalStorage package instead for .NET 5.0
Sources:
https://gist.github.com/SteveSandersonMS/ba16f6bb6934842d78c89ab5314f4b56
Comments