Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now