Specify equality comparer for model binding to collection types
Clash Royale CLAN TAG #URR8PPP Specify equality comparer for model binding to collection types I have an API where you can specify a list of names to get. Duplicate names are not allowed and if two names differ only by casing then they are considered duplicates. GET /api/people?names=john&names=alice In my own .NET code I would gather all these names in a HashSet with a custom equality comparer. HashSet var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase); But I don't think ASP.NET Core model binding is flexible enough for that. // GET /api/people?names=john&names=JOHN [HttpGet("api/people")] public GetPeople([FromQuery] HashSet<string> names) { // this works but names contains both john and JOHN } What do I have to change so that the names set only contains john and not JOHN? names 2 Answers 2 You can use a List<string> in the method heade...