0

All my controller methods have this as the first couple of lines:

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

Can I make this happen in the pipeline before a request gets to the controller? That way I can assume that the model is valid for all requests.

I use stuff in System.ComponentModel.DataAnnotations namespace to annotate my DTO classes.

Zeus82
  • 5,485
  • 8
  • 46
  • 75
  • 1
    You can handle by using global action filter http://stackoverflow.com/questions/11686690/handle-modelstate-validation-in-asp-net-web-api/11724405#11724405 – cuongle Aug 26 '16 at 20:51
  • This does not work for asp.net core – Zeus82 Aug 26 '16 at 21:23
  • Yes. So are you looking for some middleware options to validate instead of filters – lazy Aug 28 '16 at 02:54

0 Answers0