Solved

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

Posted on 2016-09-09
1
48 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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