-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
ASP.NET Core infers the parameter binding source for all API controllers following this rule:
- A previously specified
BindingInfo.BindingSourceis never overwritten. - A complex type parameter, registered in the DI container, is assigned
BindingSource.Services. - A complex type parameter, not registered in the DI container, is assigned
BindingSource.Body. - Parameter with a name that appears as a route value in ANY route template is assigned
BindingSource.Path. - All other parameters are
BindingSource.Query.
However, when the parameter type includes properties with binding source attributes the inferred source, when no attribute specified in the parameter, will be BindingSource.Body breaking the expected behavior, since all properties' attributes will be ignored as described in https://learn.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-7.0#frombody-attribute
Expected Behavior
Is expected in this case that the source is not inferred and let the binding mechanism identify based on the property's attributes.
Steps To Reproduce
[HttpPost]
public IActionResult SomeAction(Model model)
{
return Ok(model);
}
public record Model
{
[FromRoute]
public RouteModel RouteModel { get; init; }
[FromQuery]
public QueryModel QueryModel { get; init; }
[FromBody]
public BodyModel BodyModel { get; init; }
}Exceptions (if any)
N/A
.NET Version
7.0
Anything else?
Related: #45392
tvardero
Metadata
Metadata
Assignees
Labels
old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels