C#C
C#2y ago
4 replies
BlueHelmet

Blazor NavigationManager throws Unspecified navigation exeption.

So i've just started to learn Blazor. I found that when i try to use the NavigationManager from a form (OnValidSubmit), then it throws:
Microsoft.AspNetCore.Components.NavigationException: 'Exception_WasThrown'

I have not edited any of the setup (program.cs), so i might just be a bug in the framework as there is some bugs on the navigation manager. I have not been able to find any cases exactly like this on their github.

It only throws the exception in Debug, and if i continue, the navigation is executed correctly.

I have also tried to "hack", by using
NavigationManager.NavigateTo()
with the current page as parameter, throws same error.

Does anyone know if this is a known error and if there might be a workaround (or if there is something i am missing).

Code
<EditForm 
    Model="server" 
    FormName="@($"form-server-{server.ServerId}")" 
    OnValidSubmit="@(() => {DeleteServer(server.ServerId);})">
    <button type="submit" class="btn btn-primary">Delete</button>
</EditForm>

private void DeleteServer(int serverId)
{
    if (serverId > 0)
    {
        ServerRepository.DeleteServer(serverId);
        NavigationManager.Refresh();
    }
}

Exception:
See added image

See first comment for stacktrace.
image.png
Was this page helpful?