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.

The User Profile Metadata class contains property definitions for First Name, Last Name, Email, Bio, Age, Blog Url and Phone.

validating data in asp-24

It is not yet linked with the User Profile model class.

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.

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 [Display Name] attribute is used to specify a friendly name for the property under consideration.

This friendly name is used by HTML helpers such as Html. If you don't use the [Display Name] attribute a property name will be used for display purpose.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.If you don't specify any Error Message, a default error message is displayed.