ASP.NET MVC 3 Custom ValidationVersion: 1.1.0 DescriptionIn ASP.NET MVC Helpers, Forms and Validation Hands-on Lab , you have been validating data from the create and edit album forms. In this Hands-on Lab, you will use custom validation logic to control price range in the server side as well as in the client. In order to achieve that, in the first exercise you will create a custom validation property attribute and then add it to the Album model. The existing create and edit views in the StoreManager controller will process the new custom validation from the server side. In the second exercise, you will add JavaScript code and associate it to the previous custom validation, making the same views run that validation code at client side. Overview
Note:
This Hands-on Lab assumes you have basic knowledge of ASP.NET MVC and ASP.NET MVC validation. If you have not used ASP.NET MVC validation before, we recommend you to go over ASP.NET MVC Helpers, Forms and Validation Hand-on Lab.
In ASP.NET MVC Helpers, Forms and Validation Hands-on Lab, you have been validating data from the create and edit album forms. In this Hands-on Lab, you will use custom validation logic to control price range in the server side as well as in the client. In order to achieve that, in the first exercise you will create a custom validation property attribute and then add it to the Album model. The existing create and edit views in the StoreManager controller will process the new custom validation from the server side. In the second exercise, you will add JavaScript code and associate it to the previous custom validation, making the same views run that validation code at client side. Then, you will implement a custom server-side validation using ASP.NET4 IValidatableObject Interface, performing an extra validation at server side that will run after attribute validation is performed. Lastly, you will use ASP.NET MVC 3 Unobtrusive jQuery integration, executing the validation defined in the first exercise at client side with jQuery libraries. ObjectivesIn this Hands-On Lab, you will learn how to:
System RequirementsYou must have the following items to complete this lab:
SetupInstalling Code SnippetsFor convenience, much of the code you will be managing along this lab is available as Visual Studio code snippets. To install the code snippets run .\Source\Assets\CodeSnippets.vsi file. ExercisesThis Hands-On Lab is comprised by the following exercises:
Estimated time to complete this lab: 45 minutes.
Note:
Each exercise is accompanied by an End folder containing the resulting solution you should obtain after completing the exercises. You can use this solution as a guide if you need additional help working through the exercises.
Next StepExercise 1: Adding Custom Range Validation Using Validation Attributes |