BrunoZell / JsonModelBinder

An explicit json model binder to allow json serialized parts in a multipart-formdata request of a .NET-Core controller action.
MIT License
33 stars 9 forks source link

Does the JsonModelBinder work with dot net core 2 #1

Closed functional-brew closed 6 years ago

functional-brew commented 6 years ago

Hi,

I saw the reference to this library at a StackOverflow question.

Does this library work with dot net core 2, as I always get null value for the parameter decorated with
the [ModelBinder(BinderType = typeof(JsonModelBinder))] controller action method.

I had created an empty project and then installed the library via Nuget.

BrunoZell commented 6 years ago

Yes, I myself had used it with target framework netcoreapp2.0. Make sure your request looks like in the example from StackOverflow.

As an alternative, you can try to use Patrice Cotes method and don't use this NuGet package at all as it's already build in.

functional-brew commented 6 years ago

TheInsaneBro, Thanks a ton rechecked everything from the post and viola!! I can see the library in action now.

In ReadMe file, you have mentioned adding (.AddMvc().AddJsonOptions(...)) to startup.cs It would be great if you can help me with an example for adding the config?

BrunoZell commented 6 years ago

Sure. In your Startup.cs in ConfigureServices:

services.AddMvc()
    .AddJsonOptions(options =>
        options.SerializerSettings.Converters.Add(new StringEnumConverter())
        // And do other configurations for Newtonsofts JSON.Net
    );

Make sure to add the nuget package Microsoft.AspNetCore.Mvc.Formatters.Json (or Microsoft.AspNetCore.All)

Could have probably made that more clear in the readme.