I have to capture DateTime
with the following format MM/yyyy
. My view-model looks like this
public class SomeViewModel
{
public string Name { get; set; }
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? TargetMonth { get; set; }
}
Then I have razor's editor-template called Date.cshtml
with the following code
@model DateTime?
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "form-control", placeholder = ViewData.ModelMetadata.Watermark })
When I select/type value like this 07/2018
I get the following error during the client-side validation
The field Target Month must be a date.
How can I correctly capture the month using the MM/yyyy
format?