Search code examples
c#blazorblazor-server-sideidisposable

How to cancel Blazor component disposing?


With the IDisposable interface one can use the Dispose()-Method to unsubscribe from events or stop background tasks properly. But what if I have a form and check if user updates inputs and navigates back to another page. The form state gets lost. For this I want to cancel the disposing and want to show a message. Is there a way how to stop component disposing?


Solution

  • I would suggest using a ScopedService to keep the FormState in memory. Or use the LocalStorage to keep it.