DateTimePicker inside a Kendo Template

3 posts, 1 answers
  1. Kevin
    Kevin avatar
    22 posts
    Member since:
    Feb 2014

    Posted 11 Nov 2015 Link to this post

    Hi,

     

    I've placed an MVC wrapped DateTimePicker inside a kendo template, but the problem I'm having is setting the value.  Here's the code I'm using:

     

    (Html.Kendo().DateTimePicker()
                    .Name("activeTime-#=Ordinal#")
                    .Min(new System.DateTime(1970, 1, 1, 0, 0, 0)) // Epoch
                    .Format("MM-dd-yyyy HH:mm")
                    .TimeFormat("HH:mm")
                    .HtmlAttributes(new { style = "width:100%" })
                    .Value("#: kendo.toString(ActiveDT, 'MM-dd-yyyy HH:mm') #")
                    .ToClientTemplate()
                )​

     This loads a DateTimePicker inside the list view, however the value of the picker is always blank.  I've tried a few things to fix it (deferring, outputting a javascript date object instead of a string, changing everything to create the datetimepicker through javascript rather than the wrapper) and I'm at a bit of a dead end, I was just wondering where exactly I'm going wrong.

     

    Thanks,

    Kevin

  2. Answer
    Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 13 Nov 2015 Link to this post

    Hello Kevin,

    The Value method expects a DateTime value or a string that can be converted to DateTime on the server which will not be the case because the ClientTemplate is evaluated on the client. It should be possible to set the value with a template expression by setting the string to the value attribute using HtmlAttributes method:
    .HtmlAttributes(new { style = "width:100%", value = "#: kendo.toString(ActiveDT, 'MM-dd-yyyy HH:mm') #"})


    Regards,
    Daniel
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Kevin
    Kevin avatar
    22 posts
    Member since:
    Feb 2014

    Posted 13 Nov 2015 in reply to Daniel Link to this post

    That worked perfectly, thanks Daniel!

    Kevin

Back to Top