TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
First Last
NA
648
72.3k
Datetime in a model not working
Mar 30 2020 11:41 AM
I have a Asp.Net web app and I have the following date defined in my model:
[Required]
[Display(Name = "Birth Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MMM-dd-yyyy}", ApplyFormatInEditMode = true)]
[RegularExpression(@"(((0[1-9]|1[0-2])\/(0|1)[0-9]|2[0-9]|3[0-1])\/((19|20)\d\d))$", ErrorMessage = "Invalid date format.")]
public DateTime BirthDate { get; set; }
When the viewis retrieved, the birth date set to the field from the database is: 1/18/1985 12:00:00 am
I change it to: 01/18/1985 and submit the Form.
The controller server-side validation catches it as an error - invalid date format.
What am I doing wrong?
Reply
Answers (
3
)
Replacing the String having Date and Time with = and ""
Help on pushing a hidden button with javascript