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

Issue with datetime picker and non us date format

4 Answers 435 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.
Sean Cross
Top achievements
Rank 1
Sean Cross asked on 30 Jan 2011, 09:45 PM
The sp1 version of datetimepicker has some new and unusual features that cause my apps to break.

Take the following controller code:

public ActionResult ShowDate(DateTime? startDate)
{
    return View(new DateTest { StartDate = startDate.HasValue ? startDate.Value.AddDays(1) : DateTime.Today });
}

and view code:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <%
            Html.Telerik().DatePickerFor(m => m.StartDate).Render();                                                          
        %>
 
 
    <%= Html.ActionLink("Go bang", "ShowDate", new { startDate = new DateTime(2011, 1, 30) })%>
</asp:Content>

Running this code crashes for any day >= 13, giving the error "String was not recognized as a valid DateTime."  E.g pressing the Go Bang link gives [FormatException: 01/30/2011 00:00:00 is not a valid value for DateTime.]

This appeqars to be due to a combination of features/bugs

  1. DatePickerFor implicitly sets the controls Name property
  2. The control sets the date from the query string using the name property, even if the value has already been set
  3. When setting the date from the query string, the control is using the local format to decode the date rather than mm/dd
When using US date format, there is no error.  However it is still using the query string value rather than the model value which could lead to bugs if the model value differs from the query string values, as in my contrived example above.

Sean

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 31 Jan 2011, 11:42 AM
Hello Sean,

 
Straight onto described points:

#1:
This is how component should work. Html.TextBoxFor extension has the same behavior.

#2:
DatePickerFor gets the value from the provided model. If it is null, then the value from ViewData is get if there is  Key - Value pair, where key value is equal to the name of the component. As you probably notice, Html.TextBoxFor component works in the same way.

#3:
DatePicker uses $.telerik.cultureInfo.shortDate by default to parse dates. If the Globalization is turned on then the value of the shortDate will be different. 

I believe that you will need to enable globalization of the component. Check this example for more information.

Greetings,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sean Cross
Top achievements
Rank 1
answered on 31 Jan 2011, 09:11 PM
To respond to your responses

  1. Yes.  I am not complaining about that feature.
  2. That may have been how it worked before sp1, but not how it works now.  It is setting the value from the ViewData even if the view model value is not null.  In the code I supplied, the model had the value 31 Jan 2011, but the control was still trying to pull the value from ViewData.  I would say that is a bug.  
  3. I have globalization set to true. The date components are unusable without that.  However turning globalization on or off makes no difference, it still gives the conversion error.
I have attached a sample project.  Change your regional settings date format to non-us, run it and click the Go Bang link.  Instant error.
0
Accepted
Georgi Krustev
Telerik team
answered on 01 Feb 2011, 02:24 PM
Hello Sean,

Thank you for pointing this issue.

 I was able to observe the aforementioned error. I am glad to inform you that this bug is already fix and the fix will be included in the next official release of Telerik Components for ASP.NET MVC. 

For your convenience I have attached the file which include the fix. You just need to build Telerik.Web.Mvc project.

I have updated your Telerik points.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Julien
Top achievements
Rank 1
answered on 26 May 2011, 08:22 PM
Hi,

I am using the latest version of DatePicker (2011.1.315) and I've got the same error message :
String was not recognized as a valid DateTime
<%= Html.Telerik().DatePickerFor(model => model.DateDebut).ShowButton(true) %>

The culture of my project is set to "fr" culture (with date format as dd/mm/yyyy) and I set Telerik Globalization to true but when I have the day of the date (DateDebut) greater than the 12 of the month I get the error.

Thanks for your help.
Julien
Tags
Date/Time Pickers
Asked by
Sean Cross
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Sean Cross
Top achievements
Rank 1
Julien
Top achievements
Rank 1
Share this question
or