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 6111941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:41:18+00:00 2026-05-23T14:41:18+00:00

Let’s say in my model I have public DateTime Date {get;set;} property. On the

  • 0

Let’s say in my model I have public DateTime Date {get;set;} property. On the view it should be represented in a couple of textboxes – one for the Date and another for the Time.

I created two different editor templates

DateTime.cshtml:

@model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker", style = "width:90px"  })

and TimeOnly.cshtml

@model DateTime?
@Html.TextBox("", (Model.HasValue ? Model.Value.ToShortTimeString() : string.Empty), new { @class = "timePicker", style = "width:90px" })

And the EditorFor fields on the View

@Html.EditorFor(x => x.Date)
@Html.EditorFor(x => x.Date,"TimeOnly")

Now, the problem is that the actual value of Date property passed to the controller comes with default time 12:00.
The same thing happens to the Date if we change the order of the EditorFor fields – the Date rolls back to default Date value immediately after TimeOnly template has applied, although the Time part of it stays correct.

Again on the view itself the values are ok, but on submit it passes default value to the controller, either with correct Date and default Time and vice versa (it depends which template used first)

Of course I can always separate Date and Time just by adding another property to the model, but is there a better solution?

  • 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-05-23T14:41:19+00:00Added an answer on May 23, 2026 at 2:41 pm

    Scott Hanselman blogged about how a custom model binder could be used in this case.

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

Sidebar

Related Questions

Let's say that I have a method with the signature: public static bool ValidDateToSend(DateTime
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say that I have a date in R and it's formatted as follows.
Let's say that I have a model that handles recipes, and I want to
Let's say that I have a set of relations that looks like this: relations
Let's say I have an string variable called *magic_string* which value is set to
Let's say I have some view called My View. I know I can create
Let's say I have this MySQL table: OK.. see the type field? Type 0
Let's say i have this block of code, <div id=id1> This is some text
Let's say I have an image called hello.png with dimensions 200x100 . I create

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.