In terms of state management, there are a few options, listed as follows:
- Using the DI-managed objects to keep the state
- Using the ASP.NET Core session (only for the Server hosting model)
- Using the state kept in HTML elements
- Saving the state on the browser
For the DI option, this should be simple: if we inject a container service that has either a Singleton or a Scoped lifetime, any data saved to it will live up to the boundaries of that lifetime. Session storage has also been described in Chapter 4, Controllers and Actions. Saving data in HTML elements is straightforward, and, as there are no postbacks and no need to repopulate the form elements, this is much easier to achieve than with traditional web programming.
Saving the state on the browser using localStorage or sessionStorage is a different subject. One approach is to use JavaScript interoperability to directly...