I have multiple working examples in my current project of retrieving 1 query parameter from the url however when trying to follow the same convention for multiple url params, I'm receiving the following error in the chrome debugger console:
Error: System.InvalidOperationException: 'Router' cannot find any component with a route for '/confirmemail'.
my page route is defined as:
@page "/confirmemail/{Token}/{UserId}"
and the @functions{...}
section contains the following properties:
[Parameter]
string Token { get; set; }
[Parameter]
string UserId { get; set; }
I am trying to retrieve the query string parameters for a url that looks like this:
http://localhost:50466/confirmemail?Token=SomeReallyLargeToken&UserId=SomeGuidUserId
How can I achieve this?
For anyone interested in how to pass and get the parameters in the query string style
http://localhost:50466/confirmemail?Token=SomeReallyLargeToken&UserId=SomeGuidUserId
the page route doesn't change
@page "/confirmemail/"
and you should get the parameters like
protected override void OnInitialized()
{
var uri = navigationManager.ToAbsoluteUri(navigationManager.Uri); //you can use IURIHelper for older versions
if(QueryHelpers.ParseQuery(uri.Query).TryGetValue("Token", out var token))
{
var token_par = token.First();
}
if(QueryHelpers.ParseQuery(uri.Query).TryGetValue("UserId", out var userid))
{
var userid_par = userid.First();
}
}
Remember to add the following
@inject NavigationManager navigationManager
@using Microsoft.AspNetCore.WebUtilities @*for QueryHelpers*@
I'm using preview-9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With