I am just reading the Microsoft REST API Guidlines (https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md) and there are query parameters described beginning with a dollar sign, e.g. $orderBy
.
9.6 Sorting collections
The results of a collection query MAY be sorted based on property values. The property is determined by the value of the $orderBy query parameter.
Now if I try to define a method parameter like $orderBy
in an action method then it is not syntactically correct ($orderBy
is not a valid identifier).
public class ExampleController : Controller
{
// this is syntactically not correct
public IActionResult Collection(...., string $orderBy = null)
{
...
}
}
How can I access a query parameter beginning with a dollar sign in an action method of ASP.NET Core ?
The query parameters are specific to the selected API method. A default set of query parameters are displayed for the API. To add additional query parameters, use the Add query parameter button to add a new parameter to the query.
Use FromQuery
and set name [FromQuery(Name = "$orderBy")]string orderBy
:
public class ExampleController : Controller
{
public IActionResult Collection(...., [FromQuery(Name = "$orderBy")]string orderBy = null)
{
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With