Hi there,
Does anyone know the best method for validating a single form element? Or, if there is a better way to building complex forms in MVC? Just let me know.
The website I am building has complex relationships and forms that can largely be resused with little modifications.
I figure I can initialize the form with all of the elements, and the validators attached to the elements (just as you normally would). Then, rather than validating the form as a whole and submitting the whole form, I would create methods within the form that validate the fields necessary to submit (per method) and submit the form.
So, as a simple example, you could have a UserForm class that contains login(), register(), and resetPassword() methods. The login() method would validate the email and password field, then submit. The register() method would validate the same fields, but also validate company field and then proceed to submit. The resetPassword() field would validate only email. But overall, we make use of the same elements and validation.
There are far more complex examples, but this seems to be a fairly smart use of forms.