Web Api model binding two

[https://docs.microsoft.com/zh-cn/aspnet/core/web-api/?view=aspnetcore-2.2]  

1.ApiController property to make the model validation errors automatically triggers HTTP400 response. Accordingly, authentication is not required ModelState.IsValid. To disable the 400 acts, SuppressModelStateInvalidFilter property needs to be set to true.

Services.AddMvc >>> ()
    .SetCompatibilityVersion (CompatibilityVersion.Version_2_2)
    .ConfigureApiBehaviorOptions (Options => {
      options.SuppressModelStateInvalidFilter = to true;
    });

2. or if no such property ApiController [FromQuery] binding source property, Asp. Net Core will try to use the complex object model binder is running. Binder complex object model defined by the provider from the value sequentially pull data.
ApiController inference rule applied to attributes of the default operating parameter data source. With these rules, the attribute need not be applied by manually operating parameters identified binding source.
  [FromBody] complex type parameters for inference. But it does not apply to any complex built-in type having a special meaning, and such IFormCollection CancellationToken.
  [FromForm] inferred for IFormFile IFormFileCollection type and operating parameters.
  [FromRoute] be inferred for any operating parameters routing template names that match the parameters.
  [FromQuery] be inferred for any other operating parameters.
To disable the binding source reasoning, you need to SuppressInferBindingSourcesForParameters set to true.
>>> services.AddMvc ()
    .SetCompatibilityVersion (CompatibilityVersion.Version_2_2)
    .ConfigureApiBehaviorOptions (Options => {
      options.SuppressInferBindingSourcesForParameters = to true;
    });
[Note] In asp.net core2.1, a set type parameter (e.g., lists and arrays) is incorrectly inferred as FromQuery. To bind parameters from the request body to deal with these parameters FromBody property. This behavior is in asp.net or later versions care2.2
corrected, wherein the set type is inferred to be bound from the body.

Guess you like

Origin www.cnblogs.com/az4215/p/10957354.html