Date Picker and Models

2 posts, 0 answers
  1. Julian
    Julian avatar
    4 posts
    Member since:
    Oct 2017

    Posted 07 Jun Link to this post

    This is going to be a simple one for some one . It does not seem to be passing the value to my Model .

    cshtml -

                <div class="demo-section k-content">
                    @(Html.Kendo().DatePickerFor(m => m.fromDate)
                  .Name("datepicker")
                  .Value(DateTime.Today)
                  .HtmlAttributes(new { style = "width: 100%", title = "datepicker" })
                    )
                </div>

    Model

            [DisplayName("Date From (inclusive)")]
            public DateTime fromDate { get; set; }

    Controller 

        fromDate = {1/1/0001 12:00:00 AM}

     

     

     

  2. Georgi
    Admin
    Georgi avatar
    325 posts

    Posted 11 Jun Link to this post

    Hi Julian,

    Based on the provided information I assume that the issue is that the date is not sent as expected on the server. Please correct me if I am wrong.

    I have examined the provided configuration and I noticed that a name is explicitly set to the datepicker. 

    e.g.

      @(Html.Kendo().DatePickerFor(m => m.fromDate)
    .Name("datepicker")
    .Value(DateTime.Today)
    .HtmlAttributes(new { style = "width: 100%", title = "datepicker" })
      )

    The above configuration will set the name of the date picker to `datepicker`. Therefore the date will be sent to the server with a key `datepicker` not `fromDate`. 

    Have in mind that the DatePickerFor method sets the id and name attributes automatically and you can omit specifying the name explicitly.

    Could you please remove the name configuration and let me know if the fromDate field binds as expected?

    e.g.
    @(Html.Kendo().DatePickerFor(m => m.fromDate)
    .Value(DateTime.Today)
    .HtmlAttributes(new { style = "width: 100%", title = "datepicker" })
    )


    Regards,
    Georgi
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top