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

[Solved] DatePickerFor using route value rather than model value

0 Answers 67 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dave
Top achievements
Rank 1
Dave asked on 19 Jun 2012, 11:40 AM
I am passing in dates to action method in the route like this:
http://mydomain/{controller}/{action}/2012-06-19

The action method receives this value in a "startDate" parameter on the action method and it is converted into a DateTime. So far so good.

Next I construct a ViewModel that contains a StartDate property of type DateTime. The date value passed into the action method is set as the value of the ViewModel's StartDate property. This ViewModel is passed to the View.

In my view I want to display a DatePicker using this date so I have the following:

@(Html.Telerik().DatePickerFor(x => x.StartDate)

.Min(Model.VitalSign.MinimumDate))


I would expect that the DatePicker's value would be taken from the value in the ViewModel. However, the DatePicker control shows the date as "2012-06-19" instead, presumably taking the value from the RouteValues collection instead.

How do I get the DatePickerFor method to use the value from my ViewModel? I tried .DatePicker().Name("startDate").Value(Model.StartDate) but it still shows "2012-06-19" in the DatePicker control.

Regards,
Dave
Tags
Calendar
Asked by
Dave
Top achievements
Rank 1
Share this question
or