Ral*_*ing 6 c# asp.net asp.net-web-api asp.net-core
我只是阅读Microsoft REST API指南(https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md),并且有一个以美元符号开头描述的查询参数,例如$orderBy.
9.6对集合进行排序
可以基于属性值对集合查询的结果进行排序.该属性由$ orderBy查询参数的值确定.
现在,如果我尝试$orderBy在操作方法中定义方法参数,那么它在语法上不正确($orderBy不是有效的标识符).
public class ExampleController : Controller
{
// this is syntactically not correct
public IActionResult Collection(...., string $orderBy = null)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何在ASP.NET Core的操作方法中访问以美元符号开头的查询参数?
使用FromQuery和设置名称[FromQuery(Name = "$orderBy")]string orderBy:
public class ExampleController : Controller
{
public IActionResult Collection(...., [FromQuery(Name = "$orderBy")]string orderBy = null)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
617 次 |
| 最近记录: |