Upon button click, after setting the onclick event, I get this error:
Uncaught (in promise) Error: Cannot send data if the connection is not in the 'Connected' State.
What am I doing wrong for the page to not change to a valid url after button click? I'm using the NavigateTo method in the page's partial class component.
Code:
public partial class AtAGlanceComponent
{
private NavigationManager navigationManager;
public void ChangeToPage()
{
navigationManager.NavigateTo("localhost:5000/actors");
}
}
Hi @BustosAndrew
If the page is in your app, you don't need the full Uri. Just the reference that you set in @page.
navigationManager.NavigateTo("/actors", false);
If you are navigating away from your app, you need to specify "true" as a second parameter to force the server to ignore client side routing.
navigationManager.NavigateTo("https://forum.radzen.com/", true);
Regards
Paul
Thanks for the response. Didn't know the boolean parameter was also required.
Actually, after changing it to what you provided, I'm still getting the same error. @Paul_Ruston
It also makes navigation links in the sidebar not work anymore after button click.
Hi @BustosAndrew
Could be your navigationManager. It's been declared but not set to an instance. I think you may need to Inject it.
Try putting [Inject] attribute on your NavigationManager declaration
[Inject]
public NavigationManager NavigationManager { get; set; }
1 Like
@BustosAndrew
Just for future reference, when you get an error back saying "connection is not in the 'Connected' State.", it's because the app has crashed out. You can get more detailed error reporting to point you in right direction.
Stack Overflow - How to turn on CircuitOptions.DetailedErrors?
Scroll down to the Blazor Specific section.
Regards
Paul
1 Like