How To Pass Data From One Blazor Page To Another
Hello whether you are using Radzen or Visual Studio version of Blazor, you have three options
//first page
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
public partial class FirstPageComponent
{
[Inject]
ProtectedSessionStorage sessionStorage { get; set; }
//code to pass value
private async Task SetOrderID()
{
int orderID=10;
await sessionStorage.SetAsync("NewOrderID", orderID);
UriHelper.NavigateTo("SecondPage");//code to redirect to second page
}
}
//second page
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
public partial class SecondPageComponent
{
[Inject]
ProtectedSessionStorage sessionStorage { get; set; }
//code to retrieve value
private async Task GetOrderID()
{
ProtectedBrowserStorageResult result = await sessionStorage.GetAsync("NewOrderID");
if (result.Success)
{
.........................................
}
}
}