billbogaiv / hybrid-model-binding

Provides the ability to bind models using both ModelBinder and ValueProvider in ASP.NET Core.
MIT License
104 stars 19 forks source link

Failing to bind a single value to collection from query parameter #46

Closed jake-carpenter closed 4 years ago

jake-carpenter commented 4 years ago

Maybe I'm trying to do this incorrectly, but when I try to bind query parameters to a collection it will bind great as long as there are multiple, but fails when there is a single value.

An example of the code I'm attempting to use:

[ApiController]
[Route("/test")]
public class TestController : ControllerBase
{
    [HttpGet]
    public IActionResult Test(Request request)
    {
        return Ok(request);
    }
}

public class Request
{
    [HybridBindProperty(Source.QueryString)]
    public List<int> Values { get; set; }
}

Results:

https://localhost:5001/test?values=1&values=2 => {"values":[1,2]} https://localhost:5001/test?values=1 => {"values":null}

billbogaiv commented 4 years ago

Looks like this was a long-standing problem for anything not body-bound. Should be all good if you update to https://www.nuget.org/packages/HybridModelBinding/0.18.1-alpha.1

jake-carpenter commented 4 years ago

That version has solved the problem.

Thanks!