Install the following for NuGet…

Microsoft.AspNetCore.WebUtilities

Example:

https://localhost/Page1?SupplierId=123

using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Primitives;

[Inject]
public NavigationManager NavigationManager { get; set; }
public StringValues SupplierId;

    protected override async Task OnInitializedAsync()
        {
            var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);

            if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("SupplierId", out SupplierId))
            {
                Console.WriteLine("SupplierId: " + SupplierId);
            }
         }

Sources:

https://www.c-sharpcorner.com/article/working-with-query-string-or-query-parameter-in-blazor/

Last modified: February 20, 2021

Author

Comments

Write a Reply or Comment