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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:21:32+00:00 2026-06-04T18:21:32+00:00

* *UPDATE I just realized that the date is not getting data-binded during post

  • 0

**UPDATE

I just realized that the date is not getting data-binded during post at all, unless I use firefox.

Why would the browser affect the databinding on server side?

I feel like I’m taking crazy pills


My problem is that I have a JQuery date picker that seems to be formatted the right way (mm/dd/yyyy) but when the value gets posted to the server, the months and days are switched.

The date property is added to the page like this (it’s hidden just so it can bind during posts. The problem is the same if it were a simple text box):

<input type="hidden" name="SearchByDate" id="SearchByDate" value="<%: ((DateTime)Model.SearchByDate).ToString(Web.Common.Config.GetDateFormatBase) %>" />

In my view model, I specify the date format like this:

    [DisplayFormat(DataFormatString = Common.Config.GetDateFormat, 
        ApplyFormatInEditMode = true)]
    public DateTime? SearchByDate { get; set; }

My javascript datepicker is formatted like this:

        $("#appointmentDateDiv").datepicker({
------>     dateFormat: "<%= Web.Common.Config.GetDateFormatJavascript %>",
            changeMonth: true,
            onSelect: function (dateText, inst) {
                $("#SearchByDate").val(dateText);
                $("form").submit();
            }
        });

I actually sepcify the formats in a common class like this:

public const string GetDateFormatBase = @"MM/dd/yyyy";
public const string GetDateFormat = @"{0:" + GetDateFormatBase + "}"; //This is for annotations
public const string GetDateFormatJavascript = "mm/dd/yy";

As you can see, the formats are all the sam:month day year.
Everything looks good when I first load a page like this, so the datepicker lets me select a date in the right format. Then I post and if I step through my code everything still looks fine. I even re-format the date to make sure before I return to the view. But the month and day always get switched.

The strangest thing though, is that everythiing works fine in Firefox. It fails in IE, Chrome, and Opera. But I can’t see why…

  • 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-04T18:21:33+00:00Added an answer on June 4, 2026 at 6:21 pm

    Thanks, for the help guys.

    @JohnKoerner, you were right, it was a l18n problem. My Firefox was set to en-US and my other browsers were en-CA. I didn’t think they’d be different date formats but they were. This caused problems during model-binding. My solution was to use invariant culture to parse all dates in a custom model binder. I got the idea from here.

    But, I was already using a different model-binder from here. And I modified the relevant piece of code like this

    retVal = (Nullable<T>)value.ConvertTo(typeof(T), CultureInfo.InvariantCulture);
    

    where T would we the datetime that is being parsed.

    Another thing was to make sure to register the custom model binder for both DateTime and DateTime? like this:

    ModelBinders.Binders.Add(typeof(DateTime), new DateTimeModelBinder());
    ModelBinders.Binders.Add(typeof(DateTime?), new DateTimeModelBinder());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: i just realized that, how about dont allow any special characters instead of
I was just reading an update from a friend's project, mentioning the use of
I was just asked to update my settings in xcode as I was getting
I just installed Eclipse Galileo for Java developers and noticed that the update site
Update: Last night, I decided that this is just too much work to change
I just pulled https://github.com/kolanos/kohana-universe and now I'm trying to update all the modules running:
I just realized that CF3.5 doesn't support the binary formatter. I'm using it to
I just realized that there is no best way to hide MySQL string connection
Now that I was helped getting AJAX running just great, I'm having problems running
I've just realized that in different versions of Windows, and for different purposes, different

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.