Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpGet [FromQuery] Model binding fails in case of propertity with the same name #57637

Open
1 task done
FatTigerWang opened this issue Aug 31, 2024 · 2 comments · May be fixed by #58068
Open
1 task done

HttpGet [FromQuery] Model binding fails in case of propertity with the same name #57637

FatTigerWang opened this issue Aug 31, 2024 · 2 comments · May be fixed by #58068
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@FatTigerWang
Copy link
Contributor

FatTigerWang commented Aug 31, 2024

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 31, 2024
@sami-daniel
Copy link

Hello. I'm going to work on it. Can I get this one for myself?

@mitchdenny
Copy link
Member

PRs welcome

@sami-daniel sami-daniel linked a pull request Sep 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants