Skip to content

Fixes #57637 [FromQuery] Model binding fails in case of propertity with…#66837

Open
FatTigerWang wants to merge 1 commit into
dotnet:mainfrom
FatTigerWang:main
Open

Fixes #57637 [FromQuery] Model binding fails in case of propertity with…#66837
FatTigerWang wants to merge 1 commit into
dotnet:mainfrom
FatTigerWang:main

Conversation

@FatTigerWang

Copy link
Copy Markdown
Contributor

… the same name

Fixes #57637 [FromQuery] Model binding fails

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary

Note: This PR was generated with AI assistance.

Fix #57637[FromQuery] model binding fails when the parameter name matches a property name of the complex type model.

Root cause: In ParameterBinder.cs, ContainsPrefix(parameter.Name) returns true on a case-insensitive exact match (e.g., query key "Parameter" matches parameter name "parameter"). This incorrectly sets the model prefix to "parameter", causing the complex type binder to look for "parameter.Parameter" instead of just "Parameter".

Fix: For complex types, after ContainsPrefix returns true, additionally verify via GetKeysFromPrefix() that delimiter-separated sub-keys exist. If none exist (only an exact name match), fall back to empty prefix so properties bind directly.

Changes

  • src/Mvc/Mvc.Core/src/ModelBinding/ParameterBinder.cs — Added complex type check to distinguish property name collisions from true prefix matches
  • src/Mvc/Mvc.Core/test/ModelBinding/ParameterBinderTest.cs — Added 3 unit tests covering the fix, prefix usage, and simple type behavior

Test Plan

  • Complex type with property name collision (?Parameter=test) binds correctly with empty prefix
  • Explicit prefix usage (?parameter.Parameter=test) still uses parameter name as prefix
  • Simple types are unaffected by the change

Want me to create a git commit with this message?

@github-actions github-actions Bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 26, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 26, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @FatTigerWang. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@FatTigerWang FatTigerWang marked this pull request as ready for review May 26, 2026 08:01
@FatTigerWang FatTigerWang requested a review from a team as a code owner May 26, 2026 08:01
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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant