Model binding Get in Razor pages
The same options apply if you want to bind data from GET requests (which is appended to the URL as a query string).
Binding to handler method parameters is automatic and requires no additional configuration
However, by default, only values that form part of a POST request are considered for model binding when you use the BindProperty attribute. The BindProperty attribute has a property called SupportsGet, which is false by default. You have to set this to true to opt in to model binding to PageModel properties on GET requests:
Lets add Search Feature in our existing Product .Net Core App.
Open Index Page Inside Products
Add following new properties in Index Model
SearchString: Contains the text users enter in the search text box. SearchString has the [BindProperty] attribute. [BindProperty] binds form values and query strings with the same name as the property. [BindProperty(SupportsGet = true)] is required for binding on HTTP GET requests.
Genres: Contains the list of genres. Genres allows the user to select a genre from the list. SelectList requires using Microsoft.AspNetCore.Mvc.Rendering;
ProductGenre: Contains the specific genre the user selects. For example, "SKU-01".
Opting into GET binding is useful when addressing scenarios that rely on query string or route values.
To bind a property on GET requests, set the [BindProperty] attribute's SupportsGet property to true:
Navigate to the Products page and append a query string such as http://localhost:5046/Products?searchString=SKU-02
Lets add a text box for searching
The HTML <form> tag uses the following Tag Helpers:
Form Tag Helper. When the form is submitted, the filter string is sent to the Pages/Movies/Index page via query string.
Lets add a Drop down for searching
Add Drop Down in Html