Iteration 3-Validating the form
This is the third iteration of the contact Manager, and in this iteration we will add basic form validation to the Contacts manager. If the user fills out a form that is incomplete, we will block the submission of its form. In addition we have to verify the legality of the phone number and email address. (Figure 1)
Figure 1
In this iteration, we write the validation logic directly in the controller action, but this is not the approach recommended by the ASP.net MVC application. A better approach would be to deploy these validation logic to another service layer. In the next iteration we will refactor the contact Manager application to make it easier to maintain.
To make this article look intuitive, we'll write all the validation code in this iteration. Of course, we can also use some out-of-the-box validation frameworks to automate the generation of these validation codes. For example, you can use the Microsoft Enterprise Library Validation Application Block (VAB) to implement the validation logic for ASP.net mvc. For more information on VAB, please see the link below:
Http://msdn.microsoft.com/en-us/library/dd203099.aspx