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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:38:31+00:00 2026-06-03T08:38:31+00:00

My model has a object which has a date property… [Required(ErrorMessage={0} is required)] [Display(Name=Donation

  • 0

My model has a object which has a date property…

    [Required(ErrorMessage="{0} is required")]
    [Display(Name="Donation date")]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
    public DateTime DonationDate { get; set; }

The view has an editor for it….

  <div class="editor-label">
        @Html.LabelFor(model => model.Donation.DonationDate)
    </div>
    <div class="editor-field">
        @Html.TextBox("txtDate", Model.Donation.DonationDate.ToString("dd/MM/yyyy"), new { @class = "date"      })
        @Html.ValidationMessageFor(model => model.Donation.DonationDate)
    </div>

The controller just receives back the model… but when I do this in the controller and give it to another view…

ViewBag.Date = model.Donation.DonationDate;

Every time I just get back
1/1/0001 12:00:00 AM no matter what the date was set to. Any thoughts? Thanks!

Forgot to mention… I’m also using JQuery datepicker on the editor field:

    $('.date').attr("placeholder", "dd/mm/yy").datepicker({
        dateFormat: "dd/mm/yy",
        changeMonth: true,
        changeYear: true
    });
  • 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-03T08:38:32+00:00Added an answer on June 3, 2026 at 8:38 am

    You can use TextBoxFor so that the view engine knows how to label the form field appropriately (so that the model binder will recognize it on postback):

    @Html.TextBoxFor(model => model.Donation.DonationDate, new { @class = "date" })
    

    Alternatively, you could name the textbox correctly manually. I’m not sure exactly what that would look like …

    Update

    Ok, I as curious so I checked. The naming convention for nested fields uses the dot notation. So you should be able to write this:

    @Html.TextBox("Donation.DonationDate", Model.Donation.DonationDate.ToString("dd/MM/yyyy"), new { @class = "date" })
    

    Update #2

    To format the correctly, apply an attribute to the DonationDate property in your model:

    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode=true)]
    

    For this to work, you also have to use @Html.EditorFor instead of TextBoxFor.

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

Sidebar

Related Questions

Say I have a model object 'Person' defined, which has a field called 'Name'.
I have a fairly involved managed data model which has a central object with
I have a an object stored in the model called domain, which has two
I have a domain model object which has properties of type System.DateTimeOffset. I'm using
I have a data model object User . My app also has some other
I get a model object, change an attribute, save it and it still has
Which data-access model has the best performance and speed for a C# Winforms application?
i've got a Course model, which has a datetime attribute. If I look at
I have a form which has a date. I registered a customDateEditor for converting
I have a Django model for Cat which has a foreign key Dog .

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.