I'm working on a small educational project on MVC 3, and I'm facing a small problem, when attempting to handle validation in my application through a wizard.

I tried to get benefit from the ability of MVC3 to deliver content of a different view using the same URL, when handling an [HttpPost] method on a page.

I my case,my main model's class contains about ten [Required] properties, that I would like to expose through a small wizard in 3 steps , So I want that the user may be able to enter his personal informations in the first step, then respond to some questions in the second stepp and finally receive a confirmation mail from the web application whit his credentials in the last step.

I can't access the last step, because of the ModelState.isValid method that I use to handle validations, and which can't perform properly if I define some properties as [Required], but don't put them on the first view.

As the replies to those questions remain in a couple of choices, I've thinked that I may use some nullable bool? for in order to avoid validation issues, but know that it's not the proper way.

Are there someone who would like to help me find a way to extend my validation to those three steps ? Thanks in advance and sorry for my english, I'm not a native speaker.

2 Answers 2


Make a model for each page of the wizard rather than using the domain models you are probably using. Then you can separate the validation as appropriate.

  • +1 Exactly. Always use View Models rather than Domain Models, however temping it may be!
    – jkoreska
    Commented Nov 30, 2011 at 21:34

As Wyatt Barnett wrote, the most immediate solution that comes to mind is to have a specific object (one class) for each page of the wizard. If you ware using the Required annotations to make your ModelState.IsValid work, I don't think you can do it another way.

However, I think there is another way to do it as I remember I've done something very similar in Java/Struts some time ago. You could create a new class inheriting from your domain model class and add to that class just one additional property, the current step in the wizard. Now, you can't do your validation using annotations, that's the trade-off. You will have to write your own code for validating your new model (I think you have to implement the IValidatable interface) but you will be able to perform partial validations that depend on the current step in the wizard. Anyway, regardless of the chosen solution (multiple classes or one inheriting class), I think you can't use your existing annotations. The main advantage of this solution is that your wizard matches one class, so whether your wizard spans 10 different pages, or just two, the model to validate does not change, only the validation code.

Maybe you can even write some generic validation rules that will link a property to a step, and then use reflection to validate only properties of that particular step.

Also, remember that you can't really trust a "currentStep" property that comes from the client!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.