Skip to content

Add FromFormOrJsonModelBinder for mixed multipart/form-data and JSON support #61857

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

Closed

Conversation

brunohash
Copy link

Fixes #61856

This PR introduces a generic model binder (FromFormOrJsonModelBinder<T>) that enables binding from both application/json and multipart/form-data request types into a single model.

Key additions:

  • FromFormOrJsonModelBinder<T> – the core binder
  • FromFormOrJsonAttribute – attribute to annotate parameters
  • FromFormOrJsonModelBinderProvider – resolves the correct generic type
  • IFormFileReceiver – optional interface for models to receive files
  • Unit test for JSON payload support

This is useful for modern APIs that need to support clients submitting structured data along with file uploads.

Let me know if you'd like to see additional test coverage or refinements.

@brunohash brunohash requested a review from a team as a code owner May 9, 2025 19:01
@github-actions github-actions bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 9, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 9, 2025
@brunohash
Copy link
Author

@dotnet-policy-service agree

@brunohash
Copy link
Author

Hi @sebastienros — this PR introduces a lightweight generic binder to support both JSON and multipart requests. Let me know if it's something the team would consider. Happy to adapt based on feedback. Thanks!

@gfoidl
Copy link
Member

gfoidl commented May 9, 2025

Thanks for your interest and the contribution!

But as this adds members to the public APIs we have to follow the API review process.
You already did the first step, by opening the issue (can you edit the issue to follow the API Proposal issue template please?).

When API review is done, we can continue with your PR.
In the meantime I suggest that either you put the PR to draft or close it (and re-open it later in case of succesful API review).

Anyway, thanks for your effort.

@brunohash brunohash marked this pull request as draft May 9, 2025 22:22
@brunohash brunohash closed this May 9, 2025
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview5 milestone May 9, 2025
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.

📝 Issue: Native model binding support for mixed multipart/form-data and JSON payloads
2 participants