-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Yes. When building APIs that accept complex objects along with file uploads, developers often face the need to support both application/json
and multipart/form-data
. ASP.NET Core currently does not offer a unified, first-class way to bind from both content types into a single model. As a result, developers end up writing manual parsing logic inside controller actions, leading to boilerplate code and duplication across endpoints.
Describe the solution you'd like
A built-in, generic model binder (FromFormOrJsonModelBinder<T>
) that allows developers to seamlessly bind a model from either application/json
or multipart/form-data
, with optional support for file injection into the model (via an interface like IFormFileReceiver
).
This would be exposed via a [FromFormOrJson]
attribute and integrated using a custom IModelBinderProvider
.
The solution is designed to be extensible, unobtrusive, and to fit naturally into the existing ASP.NET Core model binding pipeline.
Additional context
I’ve implemented a working prototype with full unit tests and an extensibility point for models to optionally receive uploaded files. The binder automatically detects the content type, parses the payload accordingly, and applies deserialization with System.Text.Json
.
This is a common need in modern APIs, and having it supported natively would improve developer productivity and reduce error-prone boilerplate in real-world scenarios like mobile backends and admin panel APIs.