DatePicker and DateTimePicker both throw exception: Value cannot be null. Parameter name: key

2 posts, 0 answers
  1. Eddie
    Eddie avatar
    2 posts
    Member since:
    Sep 2013

    Posted 12 Sep 2013 Link to this post

    Hi,

    I have a datepicker on my cshtml view.  I'm creating it with the following line (which I'm using elsewhere successfully):
    @Html.Kendo().DateTimePicker().HtmlAttributes(new { @id = "fltBeginDate" }).Value(DateTime.Now).Format("MM/dd/yyyy")
    When the view tries to load, I get the following error:
    Value cannot be null.
    Parameter name: key

    StackTrace:
       at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
       at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
       at System.Web.Mvc.ModelStateDictionary.TryGetValue(String key, ModelState& value)
       at Kendo.Mvc.UI.InputComponentExtensions.GetAttemptedValue[T](IInputComponent`1 instance)
       at Kendo.Mvc.UI.Html.DatePickerHtmlBuilderBase.Build()
       at Kendo.Mvc.UI.DateTimePicker.WriteHtml(HtmlTextWriter writer)
       at Kendo.Mvc.UI.WidgetBase.ToHtmlString()
       at Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString()
       at System.Web.HttpUtility.HtmlEncode(Object value)
       at System.Web.WebPages.WebPageBase.Write(Object value)
       at ASP._Page_Views_PlantDeclaration_Index_cshtml.Execute()

    Any help is appreciated!

    Thanks,

    Eddie
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 13 Sep 2013 Link to this post

    Hello Eddie,

     
    I noticed that the Name method is missed in the DateTimePicker declaration. Please note that the widget requires Name to work correctly:

    @Html.Kendo().DateTimePicker().Name("fltBeginDate").Value(DateTime.Now).Format("MM/dd/yyyy")

    Regards,
    Georgi Krustev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top