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

Is `name:` supposed to allow binding to different value names? #30

Closed dynajoe closed 4 years ago

dynajoe commented 5 years ago

I'm trying to bind a model that looks like this:

   public class AccessTokenRequest
   {
      [HybridBindProperty(new[] { Source.QueryString, Source.Form }, name: "grant_type")]
      public string GrantType { get; set; }

      [HybridBindProperty(new[] { Source.QueryString, Source.Form }, name: "redirect_uri")]
      public Uri Redirecturi { get; set; }

   }

It doesn't seem that GrantType is using the grant_type parameter name. Am I misunderstanding the purpose of name?

billbogaiv commented 5 years ago

Am I misunderstanding the purpose of name?

No.

Do you have a sample available or a snippet I can look at?

You could play around with the sample project and modify IndexModel: https://github.com/billbogaiv/hybrid-model-binding/blob/0d75151b2c40bfab9136be5668e9fb34c3e2a16b/samples/AspNetCoreWebApplication/Models/IndexModel.cs#L11. Give the attribute a name like test-name and then submit a request like: http://localhost:12512/10/bill?test-name=William. The response should look like:

<h3>Age: 10</h3>
<h3>Name: William</h3>

IndexModel.cs

[HybridBindProperty(new[] { Source.Body, Source.Form, Source.QueryString, Source.Route }, name: "test-name")]
public string Name { get; set; }
billbogaiv commented 4 years ago

Closing due to inactivity. Feature works as-expected.