In MVC system, when model information is displayed in View, system will use the model property name as a text (display) field. It will also display all the property of the model object.
MVC application provides set of annotation to customize this kind of operation as mention below.
Display
This Display attribute sets the friendly display name for a model property. Example model property name is set as “Designation”, but UI is displayed with Title
Model:
Output:
ScaffoldColumn
DisplayForModel. In the below example “ID” field will not be displayed in the UI screen
DisplayFormat
DisplayFormat attribute handles various formatting options for a property via named parameters.
Output:
ReadOnly
ReadOnly attribute on a property will make sure that default model binder does not set the property with new value from request.
DataType
DataType attribute enables you to provide the run time with information about the specific purpose of a property. For example property type of string can hold type of password, URL or email address. Below example shows about setting the property with password data type
Code:
Output: