JsonModelBinder 2.1.1

.NET Core 1.0
dotnet add package JsonModelBinder --version 2.1.1
NuGet\Install-Package JsonModelBinder -Version 2.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonModelBinder" Version="2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonModelBinder --version 2.1.1
#r "nuget: JsonModelBinder, 2.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonModelBinder as a Cake Addin
#addin nuget:?package=JsonModelBinder&version=2.1.1

// Install JsonModelBinder as a Cake Tool
#tool nuget:?package=JsonModelBinder&version=2.1.1

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.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on JsonModelBinder:

Package Downloads
NanoCore

The project is inspired by years of tedious repetitions, continuously re-writing similar code-snippets and libraries, to handle common functionality, not related to the business domain, such as logging, data persistence, message queuing, documentation, validation and similar.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 506,622 11/29/2019
2.1.0 451 11/26/2019
2.0.0 9,530 10/4/2019
1.0.1 47,964 10/4/2017
1.0.0 1,067 10/2/2017