I just want to accept Date in ddMMyyyy format when sending. But this gives an error, for example,
The FromDate field must be a date.

But, when I set the date in MMddyyyy, it takes pkkttrfg forward.
My model
public class CompareModel { [Required] [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)] public DateTime FromDate { get; set; } [Required] [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)] public DateTime TODate { get; set; } }
My view part
<div class="form-group"> @Html.LabelFor(model => model.FromDate, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.FromDate) @Html.ValidationMessageFor(model => model.FromDate) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.TODate, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.TODate) @Html.ValidationMessageFor(model => model.TODate) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div>
source share