Validating data in asp
However, in this case our model class is an Entity Framework class.
Since the data model class is automatically created for you by the Visual Studio designer it is not recommended to modify the same class file.
The [Metadata Type] attribute accepts the type of the class that is supplying metadata information to the User Profile class (User Profile Metadata in this case).
Now, add a new controller in the Controllers folder and name it Home Controller.
For example, the [String Length] attribute used on the First Name property specifies the maximum length for First Name to be 50 and Minimum Length to be 3.
The Error Message property of the data annotation attribute indicates an error message that will be displayed in case there is any validation error.
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.
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.
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.
Id, First Name, Last Name, Email, Bio, Age, Blog Url and Phone.