Home > Blockchain >  How to send information from previous page to current page in Blazor?
How to send information from previous page to current page in Blazor?

Time:09-29

I need a flow what has 3 pages.

enter image description here

I need send information what user submit from page 1 to page 2, then to page 3.

I see https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-5.0#route-parameters-1

It means, if I want send text foo, it is very simple. But I need send many content from previous page to current page:

Treasury Secretary Janet Yellen is testifying with Fed Chairman Jerome Powell before lawmakers after Senate Republicans blocked a bill that would both fund the government and lift the borrowing limit.

and

Mr. John Doe

08:30 09/30/2021 Washington

How to archive this?

CodePudding user response:

There are several ways to accomplish this depending on how you want to implement this and the structure of the project.

  1. Using cascading parameters this will work if these other pages are actually components of one page.

  2. Using browser storage either local or session storage - local being "permanent" until manually deleted and session being only for that current session. Could potentially require you to continuously send data from the server to the browser just to receive that data back on the next page.

  3. An AppState (Youtube video) approach - essentially each client per session will have an object in MainLayout that is passed as a cascading parameter into all pages. In that object you can store whatever information you need to keep. It would be per session and depending on the amount of data could cause memory and performance issues.

Microsoft's docs on Blazor state management for some more details on session/local storage one more way (Dependency Injection).

CodePudding user response:

Inject an instance of IMemoryCache. Save whatever information you want to save with a key in the cache. Or you can use the same pattern with any other repository of your choice.

https://docs.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-5.0&pivots=server#in-memory-state-container-service-server

  • Related