Skip to content

Fix: This handles the issue where a URL parameter like ?age=null ca… #62630

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
// Other than the StringConverter, converters Trim() the value then throw if the result is empty.
model = null;
}
else if (bindingContext.ModelMetadata.IsNullableValueType && value == "null")
{
// Fix: This handles the issue where a URL parameter like `?age=null` cannot be bound to an `int?` type.
// This fix ensures that when the frontend sends a URL parameter with `null` value (e.g., `new URLSearchParams({ age: null }).toString()`),
// it correctly binds to a nullable integer (`int?`) instead of causing a binding error.
model = null;
}
else
{
model = _typeConverter.ConvertFrom(
Expand Down
Loading