Home Dashboard Directory Help
Search

A data-val-date attribute is generated for time fields in asp.net mvc 4 by fretjel


Status: 

Closed
 as Fixed Help for as Fixed


10
0
Sign in
to vote
Type: Bug
ID: 705643
Opened: 11/18/2011 6:19:01 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
1
Workaround(s)
view
3
User(s) can reproduce this bug

Description

In ASP.NET MVC 4, when you have a DateTime property in your model, with a data annotation of DataType.Time, it still generates a "data-val-date" attribute in the resulting html.
Details
Sign in to post a comment.
Posted by Zacharias Björngren on 12/14/2012 at 6:24 AM
I reported an issue related to this for Internet Explorer where it was closed as by design.

The problem I'm having is that MVC is generating the data-val-date="The field Time must be a date." attribute for DateTimes with no DataType-attribute which causes Internet Explorer to fail clientside validation for big endian datetimes: 2012-12-14 15:22. It requires the first separator to be a / instead: 2012/12-14 15:22

So even when using a custom template for the editor and my own validation for jQuery Internet Explorer runs some other validation which fails. This is not an issue on other tested browsers (Chrome, Opera, Firefox).
Posted by Vikcia on 10/15/2012 at 6:09 AM
Same problem with jquery datepicker and DateTime?. Tryed to force DateType.Text, but unsuccessfull. Found work around with removing data-val-date attribute by javascript. This is really annoying. BTW, in MVC3 I didn't see this problem.
Posted by NorthernDude on 8/8/2012 at 2:19 AM
Have you released the updated MVC runtime?
Posted by Microsoft on 5/24/2012 at 2:28 PM
Hi,

We have fixed this bug in MVC. The fix will be available in the next release of the ASP.NET MVC runtime.

Thanks,
The ASP.NET Team
Posted by Jan Anne Bijker on 5/18/2012 at 7:47 AM
I was running into the same problem. After some googling i found the solution.
I have changed my datetime field to a timespan field.

    [DataType(DataType.Time)]
    public TimeSpan Time{ get; set; }

EF will create a Time (time(7), not null) column in the related model table.

Hopefully this will solve your problems aswell.

//Jan Anne
Posted by Rnjos on 3/14/2012 at 12:39 PM
I'm seeing the same thing, for this data model:

        [UIHint("Time")]
        [DataType(DataType.Time)]
        [DisplayName("Ship Time")]
        public DateTime? StartDateTime { get; set; }

The validation is telling me:

The field Ship Time must be a date.

Thank you,

Robby
Posted by tom.allen on 12/2/2011 at 2:21 PM
Yes, I see this problem, too. Is there a workaround?

I have a DateTime field in my data model and I CANNOT USE the Edit screens generated by MVC4. When I edit a record it displays the correct Date+time, but I cannot save the unchanged record! For my field named TransactionTimestampClient I get validation error "The field TransactionTimestampClient must be a date."

here is my data model
        [DataType(DataType.DateTime)]
        [Display(Name = "TransactionTimestampClient")]
        public DateTime TransactionTimestampClient { get; set; }

Thanks
+tom allen
Posted by Microsoft on 11/29/2011 at 2:37 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by fretjel on 11/25/2011 at 12:29 AM
I'm sorry for the delay, I only got a notification for the last update, not the previous one...

What do you actually mean with "give us a video"?

It's quite easy to reproduce the behavior by simply creating a controller (and views) derived from this model class:
public class MyModel
{
    [Required, DataType.Time]
    public DateTime Time
}
and then look at the generated html for the "Create" view.
Posted by Microsoft on 11/24/2011 at 9:47 PM
Hello,

Sorry for bothering. Is there any update?

It would be greatly appreciated if you could provide us with that information as quickly as possible.

Thanks you
Posted by MS-Moderator10 [Feedback Moderator] on 11/21/2011 at 1:39 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a video?

We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by MS-Moderator01 on 11/18/2011 at 6:49 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Jan Anne Bijker on 5/18/2012 at 7:48 AM
I was running into the same problem. After some googling i found the solution.
I have changed my datetime field to a timespan field.

    [DataType(DataType.Time)]
    public TimeSpan Time{ get; set; }

EF will create a Time (time(7), not null) column in the related model table.

Hopefully this will solve your problems aswell.

//Jan Anne