ASP.NET Core will automatically bind form values
, route values
and query strings
by name. This means you can simply do this:
[HttpGet()]
public IActionResult Get(int page)
{ ... }
MVC will try to bind request data to the action parameters by name ... below is a list of the data sources in the order that model binding looks through them
Form values
: These are form values that go in the HTTP request using the POST method. (including jQuery POST requests).
Route values
: The set of route values provided by Routing
Query strings
: The query string part of the URI.
Source: Model Binding in ASP.NET Core
FYI, you can also combine the automatic and explicit approaches:
[HttpGet()]
public IActionResult Get(int page
, [FromQuery(Name = "page-size")] int pageSize)
{ ... }