How can I set Min Date and Max Date from Model class properties for Kendo Grid Date picker column

1 Answer 117 Views
Date/Time Pickers Grid
Pol
Top achievements
Rank 1
Iron
Pol asked on 20 Jan 2024, 06:19 AM

I have a model class given below in MVC. I am trying to set MinDate and MaxDate for the DatePicker

public class YourModel
{
    public DateTime Deadline { get; set; }
    public DateTime MinDate { get; set; }
    public DateTime MaxDate { get; set; }
}
Now I have the code as given, I am trying to replace the existing Mindate and MaxDate with the Model class properties. I am looking for the correct code .

@(Html.Kendo().DatePickerFor(x => x.Deadline)
    .Name("datepicker") // Set the name attribute
    .Format("MM/dd/yyyy")
    .Min(DateTime.Today) // Set the minimum date
    .Max(DateTime.Today.AddMonths(3)) // Set the maximum date (in this example, 3 months from today)
    .HtmlAttributes(new { id = "datepicker" }) // Set the ID attribute
)

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 24 Jan 2024, 07:56 AM

Hi Pol,

Thank you for the code snippets and the details provided.

In order to achieve the desired behavior, I would recommend using an Annotation for the "Deadline" property instead of setting other properties.

The following forum thread answer provides further information about this approach along with an example:

Give a try to the approach above and let me know if further assistance is needed.

Kind Regards,
Anton Mironov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

Tags
Date/Time Pickers Grid
Asked by
Pol
Top achievements
Rank 1
Iron
Answers by
Anton Mironov
Telerik team
Share this question
or