Custom ComplexTypeModelBinder doesn't work properly for Api Controllers or i do something wrong? #7707
Comments
If you are trying to bind data coming in as |
I did it but i had the same result.
I also registered my custom model binder as my first. Maybe this causes issue? If so, why it works properly with form-data? |
Have you debugged your provider and see which branch/line is failing? |
Your scenario should just work with any custom model binder as its the input formatters which do the binding here. So, remove any modifications to options related to modelbinderproviders. |
Thanks for looking into this, @kichalla. Assigning this to you to complete the investigation. |
@iyilm4z I still see you are using this binder in options https://github.com/iyilm4z/Demo.ModelBinding/blob/master/Demo.ModelBinding.Api/Startup.cs#L23 Remove it and things should start working |
@kichalla I know that default binder is already working. If i remove that line how MVC ecosystem will understand my custom ComplexTypeModelBinder for BaseAppModel? As you see, there in BaseAppModel i have some logic for my all VMs/DTOs. I really need it for the infrastructure of my architecture. |
I realized there is a typo in my earlier comment, sorry about that. What I really meant was that you should not write a custom model binder in your scenario as its the input formatters which deserialize the request body and construct the model. In your case, since your are sending data as json, the Now coming to the inheritance of the models, even though This is the reason MVC by default always sets the setting to |
Closing this issue as there's no action item on our side. |
Model binder doesn't work or i do something wrong.
Here is my implementation.
When i debug ComplexTypeModelBinder.cs of mvc with Rider, i get result below.
i choose body/raw(JSON(application/json)) and it doesn't work.
Surprisingly it works with body/form-data.
What's wrong with model binding feature of MVC? Does it behaves different for Web Api? What i'm missing?
The text was updated successfully, but these errors were encountered: