Search code examples
c#asp.net-mvcmodel-validation

How to disable MVC 4 model validation?


I am working on a project written on mvc 4 that got several instances of wizard-like behaviour - chain of few views that pass the same half-filled model. Starting from the second view controls are initially shown as non-valid (which is logical - model, passed to controller method has corresponding properties empty). Currently ModelState.Clear(); solution is used, but putting it into each method with model as an argument looks ugly. Same with approach found here Disable Model Validation in Asp.Net MVC

ModelBinders.Binders[typeof(MyModelType)] = new NonValidatingModelBinder();

Project got too many (over 100) model classes to register each one manually.

Is there simpler way (maybe key in .config) that turns off model validation completely?


Solution

  • I don't know it this could work but did you try this (bootstrap code or global.asax)

    ModelValidatorProviders.Providers.Clear();