Hamza Shah

Hamza Shah

  • NA
  • 87
  • 21.3k

Bootstrap Datetime picker is not working in edit mode and getting erro

Nov 25 2020 12:23 AM
In my attendance portal, Employee can select Date, Check In and Check Out through datetime picker. Datatype of 'Check In' and 'Check out' is "string". So in edit mode, datetime picker is not working and I'm get error of "getDate and getTime is not a function". I've also changed the datatype of Checkin and CheckOut to DateTime but then with time, date is also storing in database which i don't want to. So kindly please help me that how to solve this issue.
 
Here's my View Code
  1. <div class="col-md-3">  
  2. <label>Date <span class="text-danger">*</span></label>  
  3. <div>  
  4. @*<input class="form-control" type="text" readonly />*@  
  5. @Html.TextBoxFor(model => model.Date, "{0:dd/MM/yyyy}"new { @class = "form-control datepicker", autocomplete = "off" })  
  6. </div>  
  7. <input type="hidden" id="dtp_input2" value="" /><br />  
  8. </div>  
  9. <div class="col-md-3">  
  10. <label>Check In <span class="text-danger">*</span></label>  
  11. <div class="input-group date form_time" data-date="" data-date-format="hh:ii" data-link-field="dtp_input1" data-link-format="hh:ii">  
  12. @Html.TextBoxFor(model => model.CheckIn, "{0:hh:mm}" , new { @class = "form-control", autocomplete = "off" })  
  13. <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>  
  14. <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>  
  15. </div>  
  16. <input type="hidden" id="dtp_input1" value="" /><br />  
  17. </div>  
  18. <div class="col-md-3">  
  19. <label>Check Out</label>  
  20. <div class="input-group date form_time" data-date="" data-date-format="hh:ii" data-link-field="dtp_input3" data-link-format="hh:ii">  
  21. @Html.TextBoxFor(model => model.CheckOut, "{0:hh:mm}" , new { @class = "form-control", autocomplete = "off" })  
  22. <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>  
  23. <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>  
  24. </div>  
  25. <input type="hidden" id="dtp_input3" value="" /><br />  
  26. </div>  
  27. <div class="col-md-3">  
  28. <label>Short Leave (Hours)</label>  
  29. @Html.TextBoxFor(model => model.ShortLeave, new { @class = "form-control", Type = "decimal" , autocomplete = "off" })  
  30. </div>  
  31. </div>  
  32. <script>  
  33. $(function (){  
  34. $('.form_time').datetimepicker({  
  35. //language: 'fr',  
  36. format: 'hh:ii',  
  37. autoclose: 1,  
  38. });  
  39. });  
  40. $(function () {  
  41. $("#datepicker").datepicker({  
  42. autoclose: true,  
  43. todayHighlight: true  
  44. }).datepicker('update'new Date());  
  45. });  
  46. </script>  
And Here's my Controller Code
  1. public ActionResult Edit(int? id)  
  2. {  
  3. if (id == null)  
  4. {  
  5. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);  
  6. }  
  7. Attendance attendance = db.Attendance.Find(id);  
  8. if (attendance == null)  
  9. {  
  10. return HttpNotFound();  
  11. }  
  12. return View(attendance);  
  13. }  
  14. [HttpPost]  
  15. public ActionResult Edit(Attendance attendance)  
  16. {  
  17. if (ModelState.IsValid)  
  18. {  
  19. db.Entry(attendance).State = System.Data.Entity.EntityState.Modified;  
  20. db.SaveChanges();  
  21. return RedirectToAction("Index""Attendance");  
  22. }  
  23. return View();  
  24. }  

Answers (1)