a calendar for a date type, etc.)
But browsers sometimes don't provide validation based on data types.
So we often need to implement validation by adding other annotation classes. We'll talk about
this in the coming slides.
DisplayFormat Attribute Class
The previous DataType allows you to specify what type of data to display, but it cannot specify
the detailed format of displaying that type of data.
The DisplayFormat class allows you to do this.
It mainly accepts two parameters:
a string specifying the format
a bool value indicating whether the specified format should be
applied to the input device in editing mode.
This may not be supported by browser, but you can still try to have it.
For instance, if you want to display date in "yyyy-mm-dd" format for the "ReleaseDate" property,
you can do:
means the format should be applied to the first variable.
Since we only have one ReleaseDate variable here, it is not useful, but we still need to have it
according to the syntax of 'format strings', which is discussed in the next slide.
" means the month from 01 to 12. NB: don't use "mm" here, which means minutes.
For how to code a format string, see
Custom numeric format strings: -
Custom Date and Time Format Strings:
Data Annotation – Validating data
For Data Annotation on validating data, we'll talk about the following attribute classes:
MaxLength and MinLength