I have an API action that accepts a dictionary from the query string like so:
[ApiController]
public class MyController : ControllerBase {
public async Task<ActionResult> Post(CancellationToken ct, [FromQuery(Name = "responses")] Dictionary<string, bool> responses, [FromBody] MyModelType model) { }
}
The dictionary keys describe nested properties on model (which is sent as the request body), e.g.:
Foo
Foo.Bar
Bar[2].Foo
For the first two keys above, the dictionary binding works fine (as you would expect):
POST https://localhost/MyController?responses[Foo]=true&responses[Foo.Bar]=false
However, for the third key it fails due to the square brackets:
POST https://localhost/MyController?responses[Bar[2].Foo]=false
...with responses containing a single entry with the key Bar[2. Clearly the input needs to be escaped, but I haven't been able to find any documentation for how to do this, and the following approaches have not worked:
Bar\[2\].Foo
Bar[%5B2%5D].Foo
How should I go about escaping square brackets in the query string when binding to a dictionary?
