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.
Now, add a new controller in the Controllers folder and name it Home Controller.
In this example you validate the Phone property with a regular expression for US phone numbers.
At this stage, the User Profile Metadata class is just an independent class in your project.
The [Required] attribute indicates that a property value must be provided.
The [String Length] attribute is used to specify the maximum length and optionally the minimum length for a property value.
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.
Inside, it checks whether all the properties of the model class (User Profile) contain valid values. If so, Index view is rendered by passing the profile object as the model data.
If Is Valid returns true, the data is added to the User Profile table and a success view is rendered.
Id, First Name, Last Name, Email, Bio, Age, Blog Url and Phone.
Once you create the User Profile table make sure to add an ADO.
The [Url] attribute checks whether a property value is a valid URL.