5
Answers

MVC validate bootstrap date time picker

Dorababu Meka

Dorababu Meka

8y
564
1
  1. <div class="row">  
  2.     <div class="col-xs-12 col-sm-6 col-md-6">  
  3.       <div class="form-group">  
  4.          From Date  
  5.           @Html.TextBoxFor(m => m.FromDate, new { @class = "form-control", @tabindex = "2" })  
  6.           @Html.ValidationMessageFor(m => m.FromDate, "", new { @class = "label-danger" })  
  7.                     </div>  
  8.                 </div>  
  9.  </div>  
  10.   
  11.  <div class="row">  
  12.     <div class="col-xs-12 col-sm-6 col-md-6">  
  13.       <div class="form-group">  
  14.          To Date  
  15.           @Html.TextBoxFor(m => m.ToDate, new { @class = "form-control", @tabindex = "2" })  
  16.           @Html.ValidationMessageFor(m => m.ToDate, "", new { @class = "label-danger" })  
  17.                     </div>  
  18.                 </div>  
  19.  </div>  
I need to validate like to date should be greater than or equal to from date, or if user select from date I need to block all the dates which are less than to date. I tried the following code to disable the dates before from date, but it is not working
 
  1. $("#FromDate").on("change.dp", function (e) {  
  2.     $("#ToDate").datepicker("option", "minDate", e.date);  
  3. });   
Answers (5)