I am implementing the kendo datepicker in my MVC 5 application. I am not sure for what reason the viewmodel property is not being set with what is selected in the datetimepicker
<div class="form-group">
@Html.LabelFor(model => model.ContractStartDate, htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-6">
@*@Html.EditorFor(model => model.ContractStartDate, new { htmlAttributes = new { @class = "form-control" } })*@
@(Html.Kendo().DatePickerFor(model => model.ContractStartDate)
.Name("contractdatepicker")
.Value("10/10/2011")
.HtmlAttributes(new { style = "width: 100%" })
)
@Html.ValidationMessageFor(model => model.ContractStartDate, "", new { @class = "text-danger" })
</div>
</div>
The problem is your .Name("contractdatepicker")
. When this is rendered it will become the name and id tag on the <input>
and therefore won't bind to your viewmodel. If you omit that attribute it will automatically add the name and id ContractStartDate
. So, just remove that tag and if you refer to it in javascript change the reference to #ContractStartDate
.