DataAnnotation to display month name

2.1k views Asked by At

How to display the full month name and year in DataFormatString?(November-2014)

I tried using this DataAnnotation,but it does not give me the desired o/p:

 [DisplayFormat(DataFormatString="0:MMMM-yyyy")]
2

There are 2 answers

0
Soner Gönül On BEST ANSWER

I don't know it makes a difference or not but how about;

[DisplayFormat(DataFormatString = "{0:MMMM-yyyy}")]

From DisplayFormatAttribute.DataFormatString property

The formatting string can be any literal string and usually includes a placeholder for the field's value. For example, in the formatting string "Item Value: {0}", the field's value is substituted for the {0} placeholder when the string is displayed in the DynamicField object. The remainder of the formatting string is displayed as literal text.

If the formatting string does not include a placeholder, the field's value from the data source is not included in the final display text.

0
mellis481 On

You're missing brackets:

[DisplayFormat(DataFormatString="{0:MMMM-yyyy}")]