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

v 2011-1-315 Error: String was not recognized as a valid DateTime.

0 Answers 125 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.
Evgeny
Top achievements
Rank 1
Evgeny asked on 04 Apr 2011, 08:37 AM
My Region settings are Russian
Short Date: dd.MM.yyyy

After I'm set DatePicker to 30 march 2011 i have error.
Please advise.



Code:
@{
 DateTime dt = DateTime.Parse("30.03.2011"); // 30 march 2011
 Html.Telerik().DatePicker().Name("datestart").Value(dt).Render(); <-- String was not recognized as a valid DateTime eror
 }

Stack Trace:
String was not recognized as a valid DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: String was not recognized as a valid DateTime.
 
Source Error:

Line 28:                 @{
Line 29:                     DateTime dt = DateTime.Parse("30.03.2011");
Line 30:                     Html.Telerik().DatePicker().Name("datestart").Value(dt).Render();
Line 31:                     }
 
Source File: d:\Projects\EdiShop2011\Shop.Bezant\Views\Order\Index.cshtml    Line: 30
Stack Trace:
 
[FormatException: String was not recognized as a valid DateTime.]
   System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +3211050
   System.DateTime.Parse(String s, IFormatProvider provider) +28
   System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +258
 
[FormatException: 30.03.2011 is not a valid value for DateTime.]
   System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) +452
   System.Web.Mvc.ValueProviderResult.ConvertSimpleType(CultureInfo culture, Object value, Type destinationType) +249
 
[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) +386
   System.Web.Mvc.ValueProviderResult.UnwrapPossibleArrayType(CultureInfo culture, Object value, Type destinationType) +259
   System.Web.Mvc.ValueProviderResult.ConvertTo(Type type, CultureInfo culture) +83
   Telerik.Web.Mvc.UI.InputComponentExtensions.GetValue(IInputComponent`1 instance, Func`2 converter) +404
   Telerik.Web.Mvc.UI.Html.DatePickerHtmlBuilder.InputTag() +232
   Telerik.Web.Mvc.UI.Html.DatePickerHtmlBuilder.Build() +365
   Telerik.Web.Mvc.UI.DatePicker.WriteHtml(HtmlTextWriter writer) +102
   Telerik.Web.Mvc.UI.ViewComponentBase.Render() +131
   Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render() +55
   ASP._Page_Views_order_Index_cshtml.Execute() in d:\Projects\EdiShop2011\Shop.Bezant\Views\Order\Index.cshtml:30
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +272
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
   System.Web.WebPages.StartPage.RunPage() +58
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +94
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +173
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +220
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Tags
Date/Time Pickers
Asked by
Evgeny
Top achievements
Rank 1
Share this question
or