There must be problem with the class that you use the how session is going to save in class object. You need to call by string or int
in GetItemAsync<int> like this
Blazor Update NavMenu
Hello
I am looking for updating the NavMenu.razor menu, from information obtained in the pages, via a session
I have a project that references Blazored.SessionStorage
The SetItemAsync method works perfectly.
However, when I try to retrieve the information by GetItemAsync or ContainKeyAsync, the program stop
The program is available on
https://github.com/actiproj/TestSessionNavMenu
Kind regards
2 answers
Sort by: Newest
-
Prathamesh Shende 376 Reputation points
2021-12-04T11:08:51.257+00:00 -
Zhi Lv - MSFT 32,046 Reputation points Microsoft Vendor
2021-11-26T03:09:56.1+00:00 Hi @Franck J ,
According to your sample code, you are creating a Blazor Server application and use the Blazored SessionStorage, right?
I have tested your code on my side, if I set debugger on the GetItemAsync or ContainKeyAsync part of the code in the NavMenu.razor page, the session storage related code will not run continue and there is no error and exception. But if we move this part of code from the
RecupInfo
method to theOnAfterRender
method, everything works well.The result is like this:
So, the issue might relate the Blazored SessionStorage package, it not working in the onchange event. But from the usage of the Blazored SessionStorage, we can't find any description about that.
As a workaround, you could try to move the GetItemAsync or ContainKeyAsync part of the code from the
RecupInfo
method to theOnAfterRender
method. And you could also submit feedback to Blazored SessionStorage.Besides, you could also try to use the Protected Browser Storage to store the data, see ASP.NET Core Protected Browser Storage
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.Best regards,
Dillion