I want to model bind a collection of objects in a HTTP GET like so:
public class Model
{
public string Argument { get; set; }
public string Value { get; set; }
}
[HttpGet("foo")]
public IActionResult GetFoo([FromQuery] IEnumerable<Model> models) { }
Firstly, what is the default behaviour in ASP.NET Core in this scenario? The model binding documentation is sparse but does say I can use property_name[index]
syntax.
Secondly, if the default is no good, how would I get a decent looking URL by building some kind of custom model binder that I could reuse as this is a fairly common scenario. For example if I want to bind to the following format:
?Foo1=Bar1&Foo2=Bar2
So that the following objects are created:
new Model { Argument = "Foo1", Value = "Bar1" }
new Model { Argument = "Foo2", Value = "Bar2" }