Where should validation reside when using ViewModels with MVC (MVVM), on the Model or the ViewModel? (Or both or neither)? And why? I bring this up especially in light of V2 of ASP.NET MVC coming out soon.
What about complex/custom validation?
Where should validation reside when using ViewModels with MVC (MVVM), on the Model or the ViewModel? (Or both or neither)? And why? I bring this up especially in light of V2 of ASP.NET MVC coming out soon.
What about complex/custom validation?
I would say it is often needed to validate at all levels :)
I was thinking for a while about following:
NOTE: I included the Required Email into both 2 and 3 as it often depends where it belongs.
If the Email plays only informative role - then the validation can be relaxed and push it to the view-model. If Email is a strong requirement for the application - it is definitely model validation.
The 4th thing has actually nothing to do with validation as we understand it.
But it should also be applied. Thus its result should be displayed to user.
Basically all 4 types of validation can use the same infrastructure. But the implementation depends :)...
Cheers,
Dmitriy.