I need to capture date and time both for my model property. In my model class I have the following
[Required]
[DataType(DataType.DateTime)]
public DateTime?
I couln't solve it by the others answers. In my case, using TextBoxFor wasn't mandatory; I used TextBox instead.
Model
[Required(ErrorMessage = "Required")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime MyDate{get;set;}
View
@Html.TextBox("MyDate", DateTime.Now.ToString(), new {@type="datetime"})