JsonModelBinder 2.0.0

An explicit json model binder to allow json serialized parts in for example a multipart-formdata request of a .Net-Core controller action.

Install-Package JsonModelBinder -Version 2.0.0
dotnet add package JsonModelBinder --version 2.0.0
<PackageReference Include="JsonModelBinder" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonModelBinder --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

JsonModelBinder

This library provides an explicit json model binder to allow json serialized parts in a multipart-formdata request of a .Net-Core controller action.

Install-Package JsonModelBinder

Now you can, for example, have a file upload action with additional data about the upload as a json structure. Then your controller upload action would look like this:

[HttpPost]
public IActionResult Upload([ModelBinder(BinderType = typeof(JsonModelBinder))] JsonModel model, IFormFile file) {
    // model is now deserialized from the formdata-part named 'model'
    // file represents the file sent in the formdata-part named 'file'
    return Ok();
}

An valid request for the above action would be a POST with content-type: multipart/form-data with two parts specified: model (the json string according to the model type) and file (the form-data file). The model binder will take care of the deserialization process and will provide you with a concrete model class as specified in the controller action signature.

The JsonModelBinder will use the defined MvcJsonOptions from startup (.AddMvc().AddJsonOptions(...)). If these options are not available the default Json.Net settings will be used to deserialize the model.

JsonModelBinder

This library provides an explicit json model binder to allow json serialized parts in a multipart-formdata request of a .Net-Core controller action.

Install-Package JsonModelBinder

Now you can, for example, have a file upload action with additional data about the upload as a json structure. Then your controller upload action would look like this:

[HttpPost]
public IActionResult Upload([ModelBinder(BinderType = typeof(JsonModelBinder))] JsonModel model, IFormFile file) {
    // model is now deserialized from the formdata-part named 'model'
    // file represents the file sent in the formdata-part named 'file'
    return Ok();
}

An valid request for the above action would be a POST with content-type: multipart/form-data with two parts specified: model (the json string according to the model type) and file (the form-data file). The model binder will take care of the deserialization process and will provide you with a concrete model class as specified in the controller action signature.

The JsonModelBinder will use the defined MvcJsonOptions from startup (.AddMvc().AddJsonOptions(...)). If these options are not available the default Json.Net settings will be used to deserialize the model.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.0 143 10/4/2019
1.0.1 16,380 10/4/2017
1.0.0 293 10/2/2017