I have a Kendo DateTimePicker control in an mvc (asp.net) partial view that I am trying to access from document.ready():
@(Html.Kendo().DateTimePickerFor(vvm => vvm.StartTime)
.Name("dtpVisitStart")
.Format("yyyy/MM/dd HH:mm tt")
.TimeFormat("HH:mm:tt")
.Events(e => e.Change("dtpVisitStart_Change")
)
)
The javascript:
$(document).ready(function () {
TestDTP();
});
function TestDTP() {
var dtp = $("#dtpVisitStart").getKendoDateTimePicker();
debugger;
}
When the debugger line runs dtp is undefined. How can I initialize this date time picker when the partial view loads?
What I ended up doing is initializing the datetimepicker from pure javascript and ditched the razor version:
function TestDTP() {
$("#dtpVisitStart").kendoDateTimePicker({
format: "MM/dd/yyyy HH:mm tt",
timeFormat: "HH:mm",
change: dtpVisitStart_Change,
value: "@(startTime)"
});
var dtp = $("#dtpVisitStart").getKendoDateTimePicker();
debugger;
}