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

  • SEARCH
  • Home
  • 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 4039330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:35:43+00:00 2026-05-20T12:35:43+00:00

I am having a problem displaying/editing a date in MVC 3. I have set

  • 0

I am having a problem displaying/editing a date in MVC 3.

I have set up my data class property as follows (the data is actually provided by a Linq2Sql object):

[DisplayName("Date of Birth")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}", NullDisplayText = "")]
public DateTime DoB { get; set; }

In the view I then have:

@Html.TextBoxFor(m => m.DoB, new { @class = "date" })

The problem is, the text box always shows the time portion of the date, e.g. ’18/10/2010 00:00:00′

I know I can get over this problem by using a standard Html.TextBox

@Html.TextBox("DoB", Model.DoB.ToShortDateString())

but I really want to be able to control this from the data model.

I have found articles on the web that suggest that this works, but I can’t repeat their success.

Any help/advice would be appreciated.

  • 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-20T12:35:44+00:00Added an answer on May 20, 2026 at 12:35 pm

    If you want the data annotations attributes such as DisplayFormat to have any effect you should use:

    @Html.EditorFor(m => m.DoB)
    

    Checkout the following blog post from Brad Wilson which explains how model metadata works in ASP.NET MVC.

    The drawback is that now you cannot specify the class anymore. One possible solution would be to do this:

    <div class="input-date">
        @Html.EditorFor(m => m.DoB)
    </div>
    

    and then style:

    .input-date input {
        ...
    }
    

    or you could also write a custom DataAnnotationsModelMetadataProvider which would allow you to specify attributes such as class, size, maxlength, … using data annotations.

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

Sidebar

Related Questions

My problem is that I have a user that is having a problem displaying
I'm having a problem displaying data from a function to text box within a
I'm having a problem with displaying a div in with the jQuery fadeIn() command.
I'm having a problem with IE7 displaying a table (don't worry it's used for
I am having problem in displaying th Image in viewport3d of wpf. <Grid> <Image
I'm having some trouble with displaying a popup div with CSS. The problem is
Im having problems displaying records to my view when passing viewdata to a user
I'm having some problems displaying the contents of one NSArrayController in two windows defined
We're having problem with a huge number of legacy stored procedures at work. Do
I'm having problem in the following line: rd.PrintOptions.PaperSize = PaperSize.PaperFanfoldStdGerman; it throws an exception

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.