Capture exception during request deserialization in WebAPI C#

前端 未结 3 1714
-上瘾入骨i
-上瘾入骨i 2020-12-09 17:32

I\'m using WebAPI v2.2 and I am getting WebAPI to deserialise JSON onto an object using [FromBody] attribute. The target class of the deserialisation has a [OnDeserialized]

3条回答
  •  隐瞒了意图╮
    2020-12-09 17:51

    You can check ModelState.IsValid inside your controller. If "OnDeserialisedMethod" throws an exception (or any other model validation fails) it will be false, if everything succeed it will be true.

提交回复
热议问题