What is the equivalent of MVC's DefaultModelBinder in ASP.net Web API?

核能气质少年 提交于 2019-12-03 09:47:05

Take a look here for the extension points for WebApi.

There is no exact equivalent for MVC's DefaultModelBinder in WebApi.

If you are using the [FromBody] attribute then the FormatterParameterBinding will be invoked and a MediaTypeFormatter will be used to construct your model.

The model binders for the URI path and Url (Query Params) will invoke ModelBinderParameterBinding which will pass on to either a IValueProvider or a IModelBinder...

So...

In your example Field (depending on the result of content type negotiation) will use one of these: XmlMediaTypeFormatter, JsonMediaTypeFormatter or FormUrlEncodedMediaTypeFormatter. It is therefore up to you to customise the serialisation behavior of these using their respective settings e.g. JSON.NET settings... or implement your own or wrapped MediaTypeFormatter.

In your example the appId will probably be passed on to a IValueProvider... like ElementalValueProvider.

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