0
votes

I'm using Kendo Grid with editpopup and I have a DateTime field in my Model.

If I set the Max property to my datepicker, last date in datepicker not shown in editpopup field at the time of edit.

If i use below 14 its works like charm.

Code:

 @Html.Kendo().DatePickerFor(m => m.DateOfBirth).Max(DateTime.Today.AddYears(-18))).HtmlAttributes(new { placeholder = "dd/mm/yyy", type = "date", @class = "datePicker" })

But Kendo Grid shows properly.Insert Updated Working properly with last date too.

Note: I'm using MVC with Razor syntax.

enter image description here

Thanks in advance!

1
if i change my timezone to UTC its working. what is the exact solution ? - Vel
Try adding a day after you subtract the years? DateTime.Today.AddYears(-18).AddDays(1) - Matt Millican
Thanks for you response @mmillican.. I tried this already.if i add one day,date will increment in picker. but not working last date. - Vel
check if DateTime.Today is giving your required correct time and timezone value - Rajdeep

1 Answers

0
votes

I added culture to my code.it works like charm.

@Html.Kendo().DatePickerFor(m => m.DateOfBirth).Max(DateTime.Now.AddYears(-18)).HtmlAttributes(new { placeholder = "dd/mm/yyy", type = "date", @class = "datePicker" }).Culture("en-AU")

And added one more function to set the date at the time of edit.

Kendo Grid :

 .Events(events => events.Edit("dateformat"))

Jquery Function

function dateformat(e) {
  if(!e.model.isNew())
        {
            var data =e.model;
            var dob=data.DateOfBirth;
            if(dob!=null)
            {
                var parsedDate=  kendo.parseDate(dob, "dd/MM/yyyy");
                var finalDate = kendo.toString(parsedDate, "d");
                var datepicker = $("#DateOfBirth").data("kendoDatePicker");
                if(finalDate!=null)
                {
                    datepicker.value(finalDate);
                }
            }
        }