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

Weird Issue on KendoUI MVC w/ DatePicker Value

2 Answers 137 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Sig
Top achievements
Rank 1
Sig asked on 03 Aug 2012, 10:00 PM
Hey all,

I hit a confusion point recently when working with KendoUI controls inside of forms. 

Lets say I have today's date in my ViewBag (e.g. ViewBag.startDate exists with a valid date).

I've generated this control with the ASP.NET MVC kendo UI:
@Html.Kendo().DatePicker().Name("startDate").Value(@ViewBag.startDate).Format("d")

On the initial form post, this works fine.

Lets say I submit a form, causing a postback that changes the value of "startDate" in my ViewBag (on the server side).
If I print the ViewBag's startDate and then below it, generate my DatePicker control in the same way fashioned above, I get 2 different dates.  The printed one is whatever the server side changed it to, and the Kendo control has the first ViewBag.startDate.

As soon as I generate my control like this (e.g. without the "@" in front of ViewBag):
@Html.Kendo().DatePicker().Name("startDate").Value(ViewBag.startDate).Format("d")
everything seems to be fine between form posts.

This confused me for a good long while yesterday.  Does anyone know why this is?  I'm thinking it's some Razor knowledge that I may be lacking, but I'd think if it worked with or without the "@" on any attempt, it would work on every attempt.

Thanks for any help on why this is!

-Sig

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 08 Aug 2012, 11:08 AM
Hello Sig,

Actually the reason for this behavior is that the value for the DatePicker is retrieved from the ModelState. On my side there is no difference if I type @ViewBag or just ViewBag. If you want to set the value each time then I suggest you to clear the ModelState dictionary ( ModelState.Clear(); ). 

Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sig
Top achievements
Rank 1
answered on 08 Aug 2012, 05:55 PM
Thanks Petur,

Much appreciated on the guidance.  Great work on Kendo UI, I'm loving playing around with it!

-Sig
Tags
Date/Time Pickers
Asked by
Sig
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Sig
Top achievements
Rank 1
Share this question
or