Solved

Converting the web service DateTime string to the right format in MVC

Posted on 2016-09-09
1
50 Views
Last Modified: 2016-09-09
In my MVC Form

                                    <div class="form-group">
                                        @Html.LabelFor(model => model.achPayDate, htmlAttributes: new { @class = "control-label col-md-7" })
                                        @Html.DisplayFor(model => model.achPayDate)                                        
                                    </div>

in my Model
         [DisplayName("Payment Date")]
        [DataType(DataType.Date)]
        public string achPayDate { get; set; }  

      (achPayDate -- is getting data from the web service)

my achPayDate =      2016-09-21T00:00:00-07:00  
and I wanted to format that to MM/dd/yyyy  so it is 09/21/2016.  

I tried

         [DisplayName("Payment Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString=("{0:MM/dd/yyyy}"))]
        public string achPayDate { get; set; }  

which is not working
and tried

                                    <div class="form-group">
                                        @Html.LabelFor(model => model.achPayDate, htmlAttributes: new { @class = "control-label col-md-7" })
                                        @Html.DisplayFor(model => model.achPayDate, "{0:MM/dd/yyyy}")                                        
                                    </div>
and is not working

not sure what should I do
0
Comment
Question by:eli411
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
eli411 earned 0 total points
ID: 41792080
Here is what I did and it solved my problem

Found the answer myself!  Here is what I did

in the Model

        [DisplayName("Payment Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? achPayDate { get; set; }

and in the MVC form

                                    <div class="form-group">
                                        @Html.LabelFor(model => model.achPayDate, htmlAttributes: new { @class = "control-label col-md-7" })
                                        @Html.DisplayFor(model => model.achPayDate, new {@class="date"})                                        
                                    </div>
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question