Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > Documentation and tutorials > How to display a DateTime as a string?

Not answered How to display a DateTime as a string?

Feed from this thread
  • Jane avatar

    Posted on Feb 2, 2012 (permalink)

    I need to display a date as a non-modifiable string. 
    It used to show on a calendar, getting ContractStart value of type DateTime.

    <dt>@(Html.Telerik().DatePicker()
               .Name("StartDate")
               .Value((DateTime?)ViewBag.ContractStart))
            </dt>

     
    I want something like below, where ViewBag.ContractStart has been changed to a string type : 
    <dt>@(Html.Telerik().LabelFor()
                    .Name("StartDate")
                    .Value(ViewBag.ContractStart))</dt>
    but LabelFor doesn't seem to be an option. 

    Not sure how to make it work with Telerik().HtmlHelper() either.
    Links to documentation and/or examples are appreciated!

    thanks
    Jane

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Feb 3, 2012 (permalink)

    Hi,

     Why don' you output the value like this?:

    @ViewBag.ContactStart

    Regards,

    Atanas Korchev
    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

    Reply

  • Jane avatar

    Posted on Feb 3, 2012 (permalink)

    It shows correct string initially, but when ViewBag.StartDate value is updated it is not shown.

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Feb 6, 2012 (permalink)

    Hello,

     I am sorry but I don't understand what the problem is. An ASP.NET MVC view will display all updated values once rendered.

    Regards,
    Atanas Korchev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Jane avatar

    Posted on Feb 6, 2012 (permalink)

    When the page loads, ViewBag.StartDate has a value, and it is displayed correctly. 
    However, a user gets to  change other values on the page (select different entries in drop downs, etc..), which causes ViewBag.StartDate value to be set to a different date.   The page is not rendered again, but I need the updated value to show up.

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Feb 7, 2012 (permalink)

    Hello,

     I still don't understand what the problem is. How is the ViewBag.StartDate updated without a request to the server side?

    All the best,
    Atanas Korchev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Jane avatar

    Posted on Feb 7, 2012 (permalink)

    There is a request to the server side, the ViewBag is updated on the server call. 

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Feb 7, 2012 (permalink)

    Hi,

     Perhaps you can return the date as a result of this server request and update it in the view using JavaScript. Even if there were a component showing readonly dates you still would need to update it using code in this case.

    Kind regards,
    Atanas Korchev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Jane avatar

    Posted on Feb 7, 2012 (permalink)

    Yes, that would be fine.
    Can you point me to an example, or documentation for relevant JavaScript calls?  

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Feb 7, 2012 (permalink)

    Hello,

     Since we don't offer this behavior out of the box we don't have any examples or documentation. You can however search online 

    All the best,
    Atanas Korchev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > Documentation and tutorials > How to display a DateTime as a string?