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

Fixes dictionary binding error for numeric key/value #59911

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ebalders
Copy link

Fix Dictionary with numeric binding errors

Binding a dictionary with a numeric key type on a request that doesn't include the values causes a FormatException. When the request doesn't contain the parameter name, it attempts to find prefixes based on the parameter name. Since value providers return all keys when the prefix(ModelName) is empty, it will attempt to convert every form key into the numeric type.

This avoids that when the prefix is null or empty.

Fixes #35594

@ebalders ebalders requested a review from a team as a code owner January 17, 2025 02:52
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 17, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 17, 2025
Copy link
Contributor

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

@martincostello
Copy link
Member

Could you add a test for this scenario?

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.

Model binding fails with FormatException if dictionary key is numeric type and value is missing from POST
2 participants