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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:47:07+00:00 2026-05-15T00:47:07+00:00

i have searched the web relentlessly for this and have not found anything –

  • 0

i have searched the web relentlessly for this and have not found anything – which is surprising because i would think it is such a common scenario!

Basically, on my model i have a DateTime field which i wish the user to populate through a form. I am using the Html helper to render all other parts of the form (along with validation)

So this question is in two parts…

Html Helper

Firstly, is there any way to use the Html helper to split the DateTime field to be rendered as the three constituent parts of a date: day, month, year (since i do not care about the time part). This could be rendered as text boxes, drop down lists or a combination of both.

Model Binding

And then when the form is posted, what is the best approach for binding back up to the model? I have seen Scott Hanselmann’s solution to this, but it seems a little bloated for what i need – i was hoping for a slightly more elegant solution. Is it recommended to extend DefaultModelBinder and set that as default binder (since all dates would be handled in this way) or write a class that implements IModelBionder and set it as the default binder for the DateTime type?

Thanks for all the help in advance 🙂 i’m loving MVC but it’s infuriating me that something so trivial is causing so much headaches!

  • 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-15T00:47:08+00:00Added an answer on May 15, 2026 at 12:47 am

    think i’ve worked out a decent solution to this, so i will provide an answer for any who stumble across this in future!

    With regards to the Html helper, i somehow completely overlooked creating an extension method! So eventually when it occurred to me, i wrote an extension method which basically makes calls to other methods of the Html helper to provide three fields (whether you use drop down of text inputs is your choice)

        public static string DateTime(this HtmlHelper helper, string name)
        {
            StringBuilder builder = new StringBuilder();
            string dayName = name + ".Day";
            string monthName = name + ".Month";
            string yearName = name + ".Year";
    
            builder.Append(helper.TextBox(dayName));
            builder.Append(helper.DropDownList(monthName, typeof (Months)));
            builder.Append(helper.TextBox(yearName));
    
            return builder.ToString();
        }
    

    As for the binding after a form post, i simply created a class which implemented IModelBinder and set it as default for DateTime type on application start. This can then be overridden at a controller action level should a different method of binding be required. This was essentially a simpler version of Scott’s binder which i linked to in my question.

    Works like a charm at the moment (if a little simplistic), but i’m sure it’ll be enough of a foundation for anyone else who is mystified by this problem!

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

Sidebar

Related Questions

I have searched the web for hours but I can not find anything about
I have searched the web and have found no definitive solution, so here goes:
Windows Forms, VB. I have searched the web for the correct answer to this
I have searched all over the web with no luck of making this project
I have searched the forums and all over the web and have not really
I have searched the web for resolution of this error, but everything I have
I have searched this web looking for an answer, but it seems that this
I have searched the web for the answer and have found quite a few
I have searched the web for this but so far got nowhere. I have
I have this problem for a long time now, I have searched the web

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.