This is the fifth post in what is becoming a mini-series:
- ASP.NET MVC: Adding client-side validation to ValidatePasswordLengthAttribute
- ASP.NET MVC: Adding client-side validation to ValidatePasswordLengthAttribute in ASP.NET MVC 3 Preview 1
- ASP.NET MVC: Adding client-side validation to PropertiesMustMatchAttribute
- ASP.NET MVC: Adding client-side validation to PropertiesMustMatchAttribute in ASP.NET MVC 3 Preview 1
- ASP.NET MVC: ValidatePasswordLength and PropertiesMustMatch in ASP.NET MVC 3 RC2 (this post!)
In previous posts we looked at how to convert the ValidatePasswordLength and PropertiesMustMatch attributes from the ASP.NET MVC template to include client-side validation and then looked at the validation improvements in ASP.NET MVC 3 Preview 1. Writing about pre-release technology has some inherent risks, and there have been further changes to the validation infrastructure so this post reviews the situation with ASP.NET MVC 3 RC2 (which should be pretty close to the API for RTM)!
So, where does all that leave us in terms of ValidatePasswordLength and PropertiesMustMatch? Well, the good news is that they’re both now client-side enabled out-of-the-box!
ValidatePasswordLength has had client-side support added. It looks up the minimum password length from the Membership provider and then returns a client-side string length validator for that length.
PropertiesMustMatch has morphed into a new Compare attribute that is very similar to the MustMatch attribute from the previous posts.
Overall this is a step forward for the project template and for ASP.NET MVC (although I still wish that the project template didn’t use a single file under the Models folder for all of the account model classes and the validation classes and the service abstractions!)
The previous posts still give some useful information for writing custom validation attributes. At some point I may even post an example of using jQuery validate for the custom client-side validation logic…
Original post by Stuart Leeks on 17th December 2010 here: http://blogs.msdn.com/b/stuartleeks/archive/2010/12/17/asp-net-mvc-validatepasswordlength-and-propertiesmustmatch-in-asp-net-mvc-3-rc2.aspx