I need to use a specific date time format dd-MMM-yyyy HH:mm. I am getting a validation error "The field Start Date Time must be a date." when using "13-Apr-2016 11:12" which should be valid.
Razor
@using (Html.BeginForm())
{
@Html.HiddenFor(m => m.PersonId)
@(Html.Kendo().DateTimePicker()
.Name("StartDate")
.Value(Model.StartDate)
.HtmlAttributes(new { placeholder = "dd-MMM-yyyy HH:mm" })
.Format("dd-MMM-yyyy HH:mm")
.ParseFormats(new[] { "dd-MMM-yyyy HH:mm" })
.Culture("en-GB")
.TimeFormat("HH:mm"))
<input type="submit" value="OK" name="submitButton" />
}
Model
public class ConfirmPGDViewModel
{
[Required]
public long PersonId { get; set; }
[Display(Name = "Start Date Time")]
[Required]
public DateTime? StartDate { get; set; }
}
Controller
public ActionResult ConfirmPGD(long personId)
{
var viewModel = new ConfirmPGDViewModel
{
PersonId = personId,
StartDate = DateTime.Now,
};
return this.View(viewModel);
}