Praveen Kumar

Praveen Kumar

  • NA
  • 235
  • 22.5k

Dev extreme Date Format Validation Problem

Apr 27 2020 9:19 AM
Edit.cshtml
 
<div class="form-group">
@Html.LabelFor(model => model.StartDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@(Html.DevExtreme().DateBoxFor(m => m.StartDate)
.ID("startDate")
.DisplayFormat(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
.Placeholder(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
.ShowClearButton(true)
.InvalidDateMessage("The date must have the following format: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern))
@Html.ValidationMessageFor(m => m.StartDate, null, new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EndDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@(Html.DevExtreme().DateBoxFor(m => m.EndDate)
.ID("endDate")
.DisplayFormat(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
.Placeholder(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
.ShowClearButton(true)
.InvalidDateMessage("The date must have the following format: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
.OnValueChanged("endDateChange"))
<span class="text-danger field-validation-error" data-valmsg-replace="true">
<span id="spanEndDate"></span>
</span>
</div>
</div>
 
Model
 
[DisplayName("Start date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
[Required(ErrorMessage = "Start date is required")]
public DateTime? StartDate { get; set; }
[DisplayName("End date")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public DateTime? EndDate { get; set; }

Answers (1)