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

[Solved] Update DateTime Picker value from Model

1 Answer 107 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.
MFitzpatrick
Top achievements
Rank 1
MFitzpatrick asked on 17 May 2012, 02:22 PM
Hello-

I am using the DateTime picker in the following Scenario:

My date picker is bound to a View Model property called WeekEndingDate. When the user selects any date from the picker, the form is submitted. In the controller, I am taking the date the user submitted and calculating the true week ending date, e.g. the user selects a Wednesday date, I calculate the following Saturday's date. I am then assigning that week ending date to the view model property WeekEndingDate that is returned to the view. The model's WeekEndingDate that is submitted to the controller is the correct date that the user has selected. However, when the page posts, the date picker does not change to the value of WeekEndingDate that I have assigned to the Model.

Is this functionality not supported that once the user has selected a date in the date picker, the control no longer populates the date from the view model when posting?

Here is my markup:

@( Html.Telerik()
            .DatePickerFor(x => x.WeekEndingDate)
            .Name("WeekEndingDate")
            .OpenOnFocus(true)
            .HtmlAttributes(new {style = "width:100px;z-index:100;"})           
            .InputHtmlAttributes(new { style = "z-index:100;" })
            .ClientEvents(c => c.OnChange("summaryPageHandler.SubmitParameterForm")))

Thanks

Mike

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 May 2012, 07:48 AM
Hello Matt,

This is the default behavior in MVC -  when posting the value is populated from the ModelState instead of the  model passed to the View. The blog posts below explain the reason for this behavior describe some of the solutions to avoid it:

Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Date/Time Pickers
Asked by
MFitzpatrick
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or