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

HybridModelBinder.BindModelAsync doesn't respect BindPropertyAttribute #44

Closed Executor-Cheng closed 4 years ago

Executor-Cheng commented 4 years ago

Let's say we have a model like this:

public class Foo
{
    [BindProperty(Name = "barrrr")]
    public string Bar { get; set; }
}

and a action like this:

[Route("[action]")]
public IActionResult TestFoo([FromHybrid]Foo foo)
{
    return new ContentResult() { Content = foo.Bar, ContentType = "text/plain" };
}

Now I'd like to perform a httprequest, specify the foo argument by QueryString barrrr=barvalue. foo.Bar property will never be set to barvalue. But if I change [FromHybrid] to [FromQuery], it works fine.

billbogaiv commented 4 years ago

You're mixing framework attributes with HybridModelBinding. Keep [FromHybrid] and change [BindProperty... to [HybridBindProperty(new[] { Source.QueryString })] if you want the library to handle binding.

Executor-Cheng commented 4 years ago

Ok, thank you for your early reply.