Error: Action has more than one parameter bound from request body

前端 未结 6 1202
死守一世寂寞
死守一世寂寞 2021-01-11 14:15

I wrote a new method into my Controller of my ASP.Net MVC project and getting error below. I think InvalidOperationException coming from with Swagger. I marked

6条回答
  •  无人及你
    2021-01-11 14:40

    The error is coming from model binding and is not related to Swagger (the presence of ApiExplorerSettings attribute has no impact on error).

    You have two complex parameters. i.e. of Complex types

    BeverageCapacityCampaign 
    BeverageCapacity 
    

    The default for Model Binding is to bind complex parameters from the body of the request. However, only one parameter per action may be bound from body.

    So you need to either

    1. Combine them into one class that just wraps / holds both parameters as properties - and have them bound from the body (as one object)
    2. Decide which to bind from the body, and which from the route or the query and add the attributes [FromRoute] or [FromQuery] to one, and [FromBody] to the other.

    ApiExplorerSettings from System.Web.Http.Description will ignore the attributed action from a help page, or whatever else (maybe swagger)... but you will still get this exception - from problems at level of Model Binding

提交回复
热议问题