Solved

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

Posted on 2016-11-09
2
52 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
[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
2 Comments
 
LVL 28

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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