Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:52:28+00:00 2026-06-12T11:52:28+00:00

I am rendering out a DateTime field from my view model into two separate

  • 0

I am rendering out a DateTime field from my view model into two separate form fields (Date and Time). I have this line of code in my view:

@Html.TextBox("EndTime.Date", Model.EndTime.ToShortDateString())

which renders as:

<input data-val="true" data-val-date="The field Date must be a date." 
 data-val-required="The Date field is required." id="StartTime_Date"
 name="StartTime.Date" type="text" value="29/09/2012">
  • Why is this input field having the data-* attributes added to it?
  • Why does it even think it is a date?

An interesting side-effect of this unexpected validation is it causes the field to be validated as a date (which is what I want by coincidence), but jquery is deciding to use the wrong date format so I get the error:

“The field Date must be a date.”


UPDATE:
Turns out the “wrong date format” error was caused by a bug in Chrome. Because the JQuery Validation library validates a date by creating a new Date(), and because Chrome always seems to parse dates as en-US (totally ignoring the locale /language settings) it was failing when I put in en-UK dates.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:52:33+00:00Added an answer on June 12, 2026 at 11:52 am

    Why is this input field having the data-* attributes added to it?

    Because you have enabled unobtrusive validation in your application. As default, the MVC validation system enables client-side validations of both required & datatype for value types(integer, datetime).

    Why does it even think it is a date?

    When you pass a string to the Html.TextBox helper method it checks if the Model contains any property with that name and in your case the Model has a property with name EndTime and which is of type DateTime.

    You are passing EndTime.Date that still represents the type DateTime(DateTime has a property Date which is of type DateTime contains only the date component) and so the two validations are enabled by MVC.

    I would suggest you two create two different properties to store the date and time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am rendering out a ViewUserControl (.ascx file) in a view: <% Html.RenderPartial(Comments, Model.Comments);
I am rendering out a partial view like so: <div id=cart> <%Html.RenderPartial(Cart, Model); %>
I have the following Hello World code to try out TeX rendering with matplotlib
Nowadays we have pretty advanced tools to iron out rendering, allowing to see the
I have a model with a DateTime property that in one place is placed
I have some HTML that I am rendering out to a PDF file with
I'm having trouble rendering out a template, my data looks like this: var data
I can not figure out why my rich:dataTable is not rendering. I am using
I am trying to work out what is going on with regards to rendering
I'm rendering a DropDownList in my Visual Studio 2005 ASP.NET code behind page out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.