Blazor WebAssembly: How to re-render component/element after it's been removed from the DOM?

34 Views Asked by At

I am learning Blazor, and I'm working on a form for creating a resource.

If the API responds with a success response, I want to show an alert.

I am using Bootstrap's dismissable alerts.

Currently I just have the HTML for the alert behind an if (@IsSuccess) block, and set IsSuccess to true after verifying a successful response.

The alert shows up after the first successful creation, but not for any subsequent ones. That's because when the alert is dismissed, the element is completely removed (per Bootstrap's documentation).

So instead I should probably need to render a new alert element after each successful creation. I know how to do it with plain JavaScript, but I'm struggling to figure out how to express this in Blazor.

Tried putting the alert HTML into a Razor component, and putting the Razor component inside the if block, but with this approach the alert doesn't even render after the first successful create.

Appreciate any tips!

0

There are 0 best solutions below