允许参数名称具有" ["在ASP.Net核心WEB API中

时间:2017-06-01 15:05:31

标签: asp.net-web-api asp.net-core asp.net-core-mvc asp.net-web-api-routing

我的行动方法应该如下:

 public IActionResult GetAll([FromQuery]string page[Number],[FromQuery]string page[Size])
  {
     //code
  }

HTTP Request is like: "GetAll?page%5Bnumber%5D=0&page%5Bsize%5D=100".

问题:参数名称不允许我使用方括号。

1 个答案:

答案 0 :(得分:2)

此外,我会选择更简单的参数名称,您可以使用字典来解决这个问题:

public IActionResult GetAll(Dictionary<string, string> page) {
  var x = page["Number"];
  var y = page["Size"];
}