I have an Edit view that I use for creating and editing Users. The view has Password1
and Password2
fields, for password and confirmation respectively. These are not marked as required in the view model, as when editing a user, these fields are optional, only used to change a password.
I would not like to have two almost exactly the same view models, differing only by two Required
attributes. I do have server validation for these fields, but I have a real dislike for the two-phase validation, where a user fixes all client validation errors, only to submit and wait, and then be presented with server validation errors.
Is there some way I can switch client validation on for these fields in certain cases? I know I can use jQuery to add the necessary attributes, but I was hoping for a simpler and cleaner solution.