Display and Edit Annotation:-

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:

      
         [Display(Name= "Title")]
        public string Designation { get; set; }
     
     

Output:



ScaffoldColumn

DisplayForModel. In the below example “ID” field will not be displayed in the UI screen

      
    [ScaffoldColumn(false)]
    public string ID { get; set; }


DisplayFormat

DisplayFormat attribute handles various formatting options for a property via named parameters.

      
    [DisplayFormat (ApplyFormatInEditMode= true , DataFormatString ="{0:c}")]
    public decimal Salary { get; set; }
     
     

Output:



ReadOnly

ReadOnly attribute on a property will make sure that default model binder does not set the property with new value from request.

      
    [ReadOnly (true)]
    public string Designation { get; set; }
     
     

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:

      
    [DataType(DataType.Password)]
    public string Password { get; set; }
     
     

Output: