DateFormat on DisplayFor not working
- by user335160
I've set the Data Annotation for date, it works when I use the EditorFor but when I use the DisplayFor it is not working.
The date is come from a collection of data. I get this format 8/13/2011 12:00:00 AM instead of 8/13/2011. What is wrong with the code.
Data Annotation for Date
[DisplayName("Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[Required(ErrorMessage = "Date required.")]
public object EM_Date { get; set; }
View Code
@foreach (EventViewModel item in Model)
{
<tr>
<td class="AdBoxBodyRow1" style="text-align: center"> @Html.DisplayFor(modelItem => item.EM_Date) </td>
</tr>
}