问题
As far as I understand, Web Api uses Newtonsoft (JSON.NET) serializer/deserializer when model binding. But when I use [JsonProperty(Required = Required.AllowNull)]
attribute for a model property, it does not work. I omit the property in JSON but model binder does not throw exception or make the ModelState.IsValid false. My questions are:
- Why does it not work if Web Api is using Json.Net? Is there a simple solution like a configuration change?
- If I have to use a custom model binder in order to use a deserializer that respects such attributes, should my model binder just implement the
IModelBinder
interface or should it inherit from some default model binder implementation?
来源:https://stackoverflow.com/questions/41793370/doesnt-asp-net-web-api-model-binding-use-newtonsoft-json-net