Validating user-input and enforcing business rules/logic is
a core requirement of most web applications. ASP.NET MVC 2 includes a
bunch of new features that make validating user input and enforcing validation
logic on models/viewmodels significantly easier. These features are
designed so that the validation logic is always enforced on the server, and can
optionally also be enforced on the client via JavaScript. The validation
infrastructure and features in ASP.NET MVC 2 are designed so that:
1) Developers can easily take advantage of the
DataAnnotation validation support built-into the .NET Framework.
DataAnnotations provide a really easy way to declaratively add validation rules
to objects and properties with minimal code.
2) Developers can optionally integrate either their own
validation engine, or take advantage of existing validation frameworks like
Castle Validator or the EntLib Validation Library. ASP.NET MVC 2’s validation
features are designed to make it easy to plug-in any type of validation
architecture – while still taking advantage of the new ASP.NET MVC 2 validation
infrastructure (including client-side validation, model binding validation,
etc).
This means that enabling validation is really easy for
common application scenarios, while at the same time still remaining very
flexible for more advanced ones.