Validating user input with c
Now that you have some idea about data annotation attributes, let's develop a simple ASP.NET MVC application that makes use of these attributes for data validation. NET MVC project and select the Empty project template.
To attach the metadata defined in the User Profile Metadata class to the User Profile class you need to add a partial class to the project and then use the [Metadata Type] attribute as shown below: As you can see the User Profile class is a partial class and has [Metadata Type] attribute on top of it.
The [Url] attribute checks whether a property value is a valid URL.
Finally, the [Regular Expression] attribute checks whether a property value matches a pattern as specified by a regular expression.
Then add a new SQL Server database named User Db to the App_Data folder and create a table - User Profile.
The User Profile table has columns as shown in the following figure: The User Profile table As you can see from the above model class, the User Profile table consists of eight columns, viz.