ASP.Net Core WEB API 中允许参数名称带有“[”

问题描述 投票:0回答:1

我的操作方法应该是这样的:

 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".

问题:参数名称不允许有方括号。

c# asp.net-core asp.net-web-api asp.net-core-mvc asp.net-web-api-routing
1个回答
2
投票

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

public IActionResult GetAll(Dictionary<string, string> page) {
  var x = page["Number"];
  var y = page["Size"];
}
© www.soinside.com 2019 - 2024. All rights reserved.