Search code examples
c#asp.net-coreasp.net-web-apiasp.net-core-mvcasp.net-web-api-routing

Allowing parameter name to have "[" in ASP.Net Core WEB API


My action method should look like:

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

Problem : the parameter name doesn't allow me to have a square bracket.


Solution

  • Besides, that I'd go for simpler names of the parameters, you can solve this by using a dictionary:

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