This question is locked. New answers and comments are not allowed.
I'm facing the following issue, having a TimePicker on your view and rely on the input validation of the TimePicker you can end in an inconsistent state.
Steps to reproduce:
1. Add the following code snippet to your view:
2. Enter a arbitrary number into the control (e.g. 9999). The TimePicker gets invalid and is highlighted according to your css-style.
3. Click on the "clock" symbol but do not select a new value.
4. The control is marked as valid.
5. Submit your form.
If your controller action is sth. like:
The the invalid ModelState is passed back to your View, which is good. However the Telerik control then throws an exception:
Steps to reproduce:
1. Add the following code snippet to your view:
<%: Html.Telerik().TimePickerFor(m => m).Format( "HH:mm" ).OpenOnFocus( true ) %>2. Enter a arbitrary number into the control (e.g. 9999). The TimePicker gets invalid and is highlighted according to your css-style.
3. Click on the "clock" symbol but do not select a new value.
4. The control is marked as valid.
5. Submit your form.
If your controller action is sth. like:
[HttpPost][ValidateAntiForgeryToken]public ActionResult Index( TimeTrackingViewModel viewModel ){ if( viewModel == null ) { throw new ArgumentNullException( "viewModel" ); } // Check wether the model is valid. if( ModelState.IsValid ) { // Removed for clarity... } return View( viewModel );}The the invalid ModelState is passed back to your View, which is good. However the Telerik control then throws an exception:
String was not recognized as a valid DateTime. Exception Details: System.FormatException: String was not recognized as a valid DateTime.Source Error: Line 1: <%@ Control Language="C#" Inherits=".....ViewUserControlBase<TimeSpan?>" %>Line 2: <%: Html.Telerik().TimePickerFor(m => m).Format( "HH:mm" ).OpenOnFocus( true ) %> Source File: ..\Shared\EditorTemplates\TimeSpan.ascx Line: 2 Stack Trace: [FormatException: String was not recognized as a valid DateTime.] System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +5958546 System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +235[FormatException: 99999 is not a valid value for DateTime.] System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +3402814 System.Web.Mvc.ValueProviderResult.ConvertSimpleType(CultureInfo culture, Object value, Type destinationType) +330[InvalidOperationException: The parameter conversion from type 'System.String' to type 'System.DateTime' failed. See the inner exception for more information.] System.Web.Mvc.ValueProviderResult.ConvertSimpleType(CultureInfo culture, Object value, Type destinationType) +896816 Telerik.Web.Mvc.UI.InputComponentExtensions.GetValue(IInputComponent`1 instance, Func`2 converter) +359 Telerik.Web.Mvc.UI.Html.TimePickerHtmlBuilder.InputTag() +170 Telerik.Web.Mvc.UI.Html.TimePickerHtmlBuilder.Build() +303 Telerik.Web.Mvc.UI.TimePicker.WriteHtml(HtmlTextWriter writer) +241 Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString() +106 Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString() +16