Solved

@Html.EditorFor displays mm/dd/yyyy rather than date

Posted on 2016-11-09
2
31 Views
Last Modified: 2016-11-11
My model has a field, CloseDate, defined as datetime.

        [Display(Name = "Close date")]
        [DataType(DataType.Date)]
        public Nullable<System.DateTime> CloseDate { get; set; }

Open in new window


It's displayed on my Edit page as follows:

@Html.EditorFor(model => model.TargetedFundingCloseDate)

Open in new window


If I enter or select a date, and click Save, the value is saved to my database. However, when the record is again displayed in Edit, I see the same mm/dd/yyyy placeholder that I did when CloseDate was null; and if I click Save, my originally selected date is saved as null.

Screen shot of CloseDate on Edit.shtml
What can I do to get around this? Have I missed something basic?
0
Comment
Question by:Bryant Farley
2 Comments
 
LVL 23

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41880910
Try..

[Display(Name = "Close date")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:HH:mm MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime CloseDate { get; set; }

Open in new window

1
 

Author Closing Comment

by:Bryant Farley
ID: 41884155
Thank you - had missed something very basic, as suspected.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to picture file 3 66
Editing XSL files, 2 40
Getting multiple values from a dataset ASP.NET(VB) 3 37
Entity Framework 7 27
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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 …

943 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

1 Experts available now in Live!

Get 1:1 Help Now