Integrating Custom Validation with ASP.NET MVC ModelState
One common pattern we see in ASP.NET MVC controller actions is a conditional check for ModelState.IsValid , with different branches getting executed based on whether the result is true or false . The ModelState captures errors arising from data annotations such as Required and StringLength . When there are custom validations that cannot be captured using data annotations, what usually happens is that these validations are checked in the success block of ModelState.IsValid . In this post we are going to talk about how to integrate custom validation into ModelState .