Previous tip (Constrained Route parameters) Next tip (Modify the query string) >>

Grab values from the query string

Sometimes it’s handy to pass parameters via the query string part of a URL (everything after the ?).

/products?instock=true

Use the SupplyParameterFromQuery attribute to populate your component’s parameter with a value from the query string (.NET 6 and later).

@page "/Product/Search"
Showing products that are @inStockMessage
@code {
[Parameter]
[SupplyParameterFromQuery]
public bool InStock { get; set; }
private string inStockMessage => InStock
? "in stock"
: "out of stock";
}