Blazor server component inside mvc doesn't show error message after unhandled exceptions

Viewed 225

I am using asp.net core 5.0 MVC application, and i've injected blazor component. It actually works, but from time to time i encounter small issues, such as: when handling exceptions that break circuit, i need to display error message for user to reload page. I've added following into _Layout.cshtml:

    <div id="blazor-error-ui">
    <environment include="Staging,Production">
        An error has occurred. This application may no longer respond until reloaded.
    </environment>
    <environment include="Development">
        An unhandled exception has occurred. See browser dev tools for details.
    </environment>
    <a href="" class="reload">Reload</a>
    <a class="dismiss"></a>
</div>

and modified site.css:

#blazor-error-ui {
  background: lightyellow;
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem 0.7rem 1.25rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 0.75rem;
  top: 0.5rem;
}

Which is in fact copy/paste from blazor server template.

But it's not working - framework is not changing #blazor-error-ui property display to block. ?

0 Answers
Related