I have this code:
CommandModel data;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
persistingSubscription = ApplicationState.RegisterOnPersisting(PersistData);
if (!ApplicationState.TryTakeFromJson<CommandModel>("data", out var restored))
{
data = new();
}
else
{
data = restored!;
(name, argument) = (data.Name, data.Argument);
}
}
private Task PersistData()
{
ApplicationState.PersistAsJson("data", data);
return Task.CompletedTask;
}
void IDisposable.Dispose()
{
persistingSubscription.Dispose();
}
string name, argument = null;
private async Task OnSubmitLinkAsync()
{
data = MyLinkData; //<<
(name, argument) = (MyLinkData.Name, MyLinkData.Argument);
}
[SupplyParameterFromForm(FormName = "post-link")]
private CommandModel MyLinkData { get; set; } = new();
private sealed class CommandModel
{
public string Name { get; set; } = "";
public string Argument { get; set; } = "";
}
it is In blazor static ssr mode, But after submitting the data and then refreshing the page or submit another form the data is cleared. and not persisted.
So is data persistence working in static ssr mode and if yes how to correct this code?