This code will help you to understand how to get the query parameter from the URL using NavigationManager in ASP.NET Core Blazor.
Generally, a query string stores values in a URL that are visible to users. It is mostly used to pass the data from one page to another.
In Blazor, the query string can be added using NavigationManager. To access query parameter:
@page "/queryparam" @inject NavigationManager UriHelper <h3>Query Paramter Demo</h3> <button @onclick="Navigate">Click</button> <div>Id = @Id</div> @code { string Id { get; set; } void Navigate() { var query = new Dictionary<string, string> { { "Id", "1001" } }; navManager.NavigateTo(QueryHelpers.AddQueryString(navManager.Uri, query)); var uri = navManager.ToAbsoluteUri(navManager.Uri); if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("Id", out var param)) { Id = param.First(); } } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Generally, a query string stores values in a URL that are visible to users. It is mostly used to pass the data from one page to another.
In Blazor, the query string can be added using NavigationManager. To access query parameter:
- Install the package Microsoft.AspNetCore.WebUtilities from NuGet.
- Use the QueryHelpers.ParseQuery.TryGetValue method.
need an explanation for this answer? contact us directly to get an explanation for this answer