Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

PersistentState Not Persisting Data On Internal Navigation through Enhanced Navigation In Blazor Web App WebAssembly Interactivity

$
0
0

I have following code In my Blazor Web App WebAssembly Interactivity project Using .NET10 LTS:
The problem i am facing is that on internal navigation to this component(i.e counter) through enhanced navigation, the data in CurrentCount is not persisted. I mean even after using PersistentState(AllowUpdates = true)] CurrentCount is always null when OnInitializedAsync is called as a result of which (CurrentCount == null) is always true in both condition prerendering and hyrdation too. But when this component is reloaded the data is persisted on both prerendering and hyrdation. I am trying to persist the data, How to solve this This is Blazor web app WebAssembly Interactivity.

@page "/counter"@rendermode InteractiveWebAssembly<PageTitle>Counter</PageTitle><h1>Counter</h1><p role="status">Current count: @CurrentCount</p>@code {       [PersistentState(AllowUpdates = true)]       public int? CurrentCount { get; set; }       Random random = new Random();       protected override async Task OnInitializedAsync()       {         if (CurrentCount == null)         {           CurrentCount = Random.Shared.Next(100);         }            }} 

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>