-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Model binding fails when a [FormQuery] parameter has the same name as a property of the model.
public class TestParameter
{
public string Parameter { get; set; };
}
[ApiController]
public class TestController()
{
[HttpGet("test")]
public TestParameter Test([FromQuery] TestParameter parameter)
{
return parameter;
}
}
HTTP GET /test?Parameter=test
{
"parameter": null
}
Looks like it's related to here
else if (modelBindingContext.ValueProvider.ContainsPrefix(parameter.Name)) |
When the name of the model is the same as the model attribute name, the binding intention cannot be easily determined by the prefix
Expected Behavior
HTTP GET /test?Parameter=test
{
"parameter": "test"
}
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
9.0.100-preview.7.24407.12
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templates