evgeny@zborovsky:~$

$ cat posts/web-api-2-centralised-model-state-validation.md

Web.API 2 centralised model state validation

1 min read

Model state validation is easy with DataAnnotations. However, you will find repeating the next line of code very soon:

… if(!ModelState.IsValid) return BadRequest(..); …

Luckily, there is a pretty simple solution - to use ActionFilter:

All you have to do is to add the ValidateModel attribute to your controller methods that require model state validation.