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

[Solved] How to display a DateTime as a string?

9 Answers 122 Views
Documentation and tutorials
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jane
Top achievements
Rank 1
Jane asked on 02 Feb 2012, 06:47 PM
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

9 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 03 Feb 2012, 09:23 AM
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
0
Jane
Top achievements
Rank 1
answered on 03 Feb 2012, 09:42 PM
It shows correct string initially, but when ViewBag.StartDate value is updated it is not shown.
0
Atanas Korchev
Telerik team
answered on 06 Feb 2012, 09:18 AM
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 >>
0
Jane
Top achievements
Rank 1
answered on 06 Feb 2012, 06:24 PM
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.
0
Atanas Korchev
Telerik team
answered on 07 Feb 2012, 11:23 AM
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 >>
0
Jane
Top achievements
Rank 1
answered on 07 Feb 2012, 04:10 PM
There is a request to the server side, the ViewBag is updated on the server call. 
0
Atanas Korchev
Telerik team
answered on 07 Feb 2012, 04:22 PM
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 >>
0
Jane
Top achievements
Rank 1
answered on 07 Feb 2012, 06:02 PM
Yes, that would be fine.
Can you point me to an example, or documentation for relevant JavaScript calls?  
0
Atanas Korchev
Telerik team
answered on 07 Feb 2012, 06:04 PM
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 >>
Tags
Documentation and tutorials
Asked by
Jane
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jane
Top achievements
Rank 1
Share this question
or