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

Date Picker and Models

1 Answer 620 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 07 Jun 2018, 04:00 PM

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}

 

 

 

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 11 Jun 2018, 01:42 PM
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.
Tags
Date/Time Pickers
Asked by
Julian
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or