我只是阅读Microsoft REST API Guidlines(
https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md),并且有一个以美元符号开头的查询参数,例如: $排序依据.
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.
现在,如果我尝试在操作方法中定义类似$orderBy的方法参数,那么它在语法上是不正确的($orderBy不是有效的标识符).
public class ExampleController : Controller { // this is syntactically not correct public IActionResult Collection(....,string $orderBy = null) { ... } }
解决方法
使用FromQuery并设置名称[FromQuery(Name =“$orderBy”)] string orderBy:
public class ExampleController : Controller { public IActionResult Collection(....,[FromQuery(Name = "$orderBy")]string orderBy = null) { ... } }