This is a migrated thread and some comments may be shown as answers.

[Solved] DatePickerFor Required Not Working

2 Answers 154 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tyler
Top achievements
Rank 1
Tyler asked on 02 May 2012, 04:33 PM
I am fairly new to using Telerik MVC controls. But I can not get the datepickerFor to respect the [Required] data annotations. 

I created a new MVC3 application using the telerik templates. When I run the application, the client side validation does not work.


Model Class:
 public class DateTest
    {
        [Required] //does not work
        public DateTime StartDate { get; set; }
        [Required] //works
        public string TestString { get; set; }
    }

Index.cshtml

@using (Html.BeginForm())
{
  
    <div>
    @Html.EditorFor(m => m.TestString)
    @Html.ValidationMessageFor(model => model.TestString)</div>
    
    @Html.Telerik().DatePickerFor(m => m.StartDate)
    @Html.ValidationMessageFor(model => model.StartDate)
    <input type="submit" value="Send" />
}

How do I get @Html.Telerik().DatePickerFor to respect validation rules that are applied to my model? When I view my source the data-val fields do not appear to be rendering when I use the datepickerfor() method. 

I've attached my vanilla project.

2 Answers, 1 is accepted

Sort by
0
Accepted
Pechka
Top achievements
Rank 1
answered on 03 May 2012, 07:00 AM
Yo mate,

You need to create an instance of your model and pass it to the View
0
Tyler
Top achievements
Rank 1
answered on 03 May 2012, 02:00 PM
Pechka,

Thanks that was it.


Tags
Date/Time Pickers
Asked by
Tyler
Top achievements
Rank 1
Answers by
Pechka
Top achievements
Rank 1
Tyler
Top achievements
Rank 1
Share this question
or