Error implementing a Custom Model Binder in Asp.Net Web API

流过昼夜 提交于 2019-12-06 01:00:03

The issue you are having is that you are using the MVC model binder not the WebApi. It looks like you are deriving from System.Web.Mvc.DefaultModelBinder which implements System.Web.Mvc.IModelBinder.

To create a custom model binder for WebApi you need to implement System.Web.Http.IModelBinder.

Take a look at the model binders available in WebApi e.g. the CompsiteModelBinder http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f079d76e57b5#src%2fSystem.Web.Http%2fModelBinding%2fBinders%2fCompositeModelBinder.cs.

Some useful resources here and here.

Have you considered using a JToken for your Json form field this may work without a custom binder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!