Hello on my Mainlayout page i'm using the ErrorBoundary component.
This works well for all the page's.
But is there away to do the same for all the page's im opening with the
await DialogService.OpenAsync
service ?
So can i apply a kind of Layout to all these modal page's ?
Components used in dialogs do not use layouts. Only routable pages rendered via navigation can have a layout. You can add an ErrorBoundary to the component that you open with DialogService.OpenAsync
Add a button that throws exception in the dialog page
<RadzenButton Text="Throw"
Click="@(args => throw new Exception("This is a test exception"))" />
Clicking the button shows the ErrorBoundary:
It also logs the following in the console:
warn: Microsoft.AspNetCore.Components.Web.ErrorBoundary[100]
Unhandled exception rendering component: This is a test exception
System.Exception: This is a test exception
at RadzenBlazorDemos.Pages.DialogCardPage.<>c.<BuildRenderTree>b__0_0(MouseEventArgs args) in /Users/korchev/github/radzen-blazor/RadzenBlazorDemos/Pages/DialogCardPage.razor:line 10
at InvokeStub_Func`2.Invoke(Object, Span`1)
at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Radzen.Blazor.RadzenButton.OnClick(MouseEventArgs args) in /Users/korchev/github/radzen-blazor/Radzen.Blazor/RadzenButton.razor.cs:line 154
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
If no error boundary is present the default UI exception is shown:
Works perfectly for an unhandled exception in a normal page and displays an alert; very nice. And I can reset after the users closes the alert and the user continues as normal. However, if an unhandled exception was triggered from a page that is displayed in a dialog, the alert does not display. Stepping through the code, the Alert code is triggered but no alert is displayed. There probably is a reason for this or am I missing something?
I noted that if I put something in the UI for the DisplayError razor page, that does display but no alert regardless of whether the RadzenComponent tag is in the ErrorContent or not.
Great, thank you, it's working. I went with the MainLayout version so that it applies to all pages displayed using a Dialog. The OnAfterRender made the difference as I was using the OnInitialize.
There are a couple of things that I need to look at:
The alert dialog on the normal pages now displays 2 of the same dialogs at the same time but that from the dialog page is fine
Whilst for the normal page, Recover() works to make the pages operation after the alert, it doesn't for the dialog page; not clear why this is the case.
If you have any ideas on this, I would much appreciate it. I will tomorrow have a bit more look at this as it's very very close to the solution & probably needs a slight tweak.
The body one still works fine but the dialog one has a slight issue. This is the same issue I was having with my version as well after I got the alert working based on your code.
I have a CRUD with a datagrid and a dialog that displays an Edit Page. When I trigger an exception from this edit page, the alert displays fine now, and the Recover() code executes but the Edit Page no longer displays from the datagrid afterwards. If I navigate to another page and come back to this datagrid, the edit page can now be displayed. Seems like the Recover() hasn’t quite worked.
If you are able to check this with your version, that would be great. I’m happy to create a solution & post it if you need it.