2

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 DateTime 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>
}
user335160
  • 1,364
  • 6
  • 32
  • 67

0 Answers0