This question is locked. New answers and comments are not allowed.
Greetings,
I am using the mvc datepicker in an mvc site. I'm using Mvc 2.0 and the build for 2.0.
Here is the issue:
If the user enters an incorrect date format, the datepicker client side will fire an event when the control loses focus. The textbox will turn pink indicating an error. This works as expected. However, the form can still be submitted to the server and it seems the control will simply null out the value. When my controller calls UpdateModel, it throws an error and the displays the view with the null value and hence an error is thrown as date cannot have a null value.
According to Scott Guthrie...
The UpdateModel() helper method automatically populates the ModelState collection when it encounters errors while trying to assign form values to properties on the model object. For example, our Dinner object's EventDate property is of type DateTime. When the UpdateModel() method was unable to assign the string value "BOGUS" to it in the scenario above, the UpdateModel() method added an entry to the ModelState collection indicating an assignment error had occurred with that property.
I think I discovered the bug with the datepicker. Since UpdateModel uses reflection to look for a matching property it is using the id of the control. My field is EventDate, and here is the code in the View:
<% Html.Telerik().DatePicker().Name("EventDate").Value(String.Format("{0:g}", Model.EventDate)).Render(); %>
However, when I do a view source on the form, it shows this:
<div class="t-widget t-datepicker" id="EventDate"><input class="t-input" id="EventDate-input" name="EventDate" value="5/6/2010" /><a class="t-link t-icon t-icon-calendar" href="#" tabindex="-1" title="Open the calendar">select date</a></div><span class="field-validation-valid" id="EventDate_validationMessage"></span>
Notice the id of the div is EventDate, but the id of the html control is
id="EventDate-input"
That will not match the property using reflection and hence the ModelState Error is not getting updated.
Please verify if this is indeed a bug and if there is a fix.
Many Thanks,
Ed
I am using the mvc datepicker in an mvc site. I'm using Mvc 2.0 and the build for 2.0.
Here is the issue:
If the user enters an incorrect date format, the datepicker client side will fire an event when the control loses focus. The textbox will turn pink indicating an error. This works as expected. However, the form can still be submitted to the server and it seems the control will simply null out the value. When my controller calls UpdateModel, it throws an error and the displays the view with the null value and hence an error is thrown as date cannot have a null value.
According to Scott Guthrie...
The UpdateModel() helper method automatically populates the ModelState collection when it encounters errors while trying to assign form values to properties on the model object. For example, our Dinner object's EventDate property is of type DateTime. When the UpdateModel() method was unable to assign the string value "BOGUS" to it in the scenario above, the UpdateModel() method added an entry to the ModelState collection indicating an assignment error had occurred with that property.
I think I discovered the bug with the datepicker. Since UpdateModel uses reflection to look for a matching property it is using the id of the control. My field is EventDate, and here is the code in the View:
<% Html.Telerik().DatePicker().Name("EventDate").Value(String.Format("{0:g}", Model.EventDate)).Render(); %>
However, when I do a view source on the form, it shows this:
<div class="t-widget t-datepicker" id="EventDate"><input class="t-input" id="EventDate-input" name="EventDate" value="5/6/2010" /><a class="t-link t-icon t-icon-calendar" href="#" tabindex="-1" title="Open the calendar">select date</a></div><span class="field-validation-valid" id="EventDate_validationMessage"></span>
Notice the id of the div is EventDate, but the id of the html control is
id="EventDate-input"
That will not match the property using reflection and hence the ModelState Error is not getting updated.
Please verify if this is indeed a bug and if there is a fix.
Many Thanks,
Ed