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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:36:38+00:00 2026-06-06T15:36:38+00:00

I have a page with a datetime input on it, along with the customary

  • 0

I have a page with a datetime input on it, along with the customary JQuery datepicker, and an editor template for “Date” which formats the date in the text box and the date that is passed into the view and adds the required clases etc.

When I call the page from the default action (which takes a nullable datetime for passing the date into), I get a populated date and it formats correctly (in this case dd/mm/yyyy). When I call the page with a datetime, it builds the date correctly in the action, but the page renders the date as "mm/dd/yyy hh:mm:ss", rather than the desired format. The url I’m calling the action with is <url>?reportDate=06%2F13%2F2012%2000%3A00%3A00, which is rendered from an html helper action link, passing in the model date as the parameter, and the action can translate this to the correct date. If I try to call the page with <url>?reportDate=13%2F06%2F2012 (the format I want to display the date as), the action takes it as a null parameter being passed, the page displays the date correctly, but a validation exception is thrown – The value '13/06/2012' is invalid.

I’m in the UK, I’ve got my globalization in the web.config set to en-GB, but for some reason it’s validating against the US version of the date by the looks of it.

Model:

public class ReportModel
{
    [Required]
    DataType(DataType.Date)]
    public DateTime ReportDate { get; set; }
    public string Message { get; set; }

    //More code here
}

Template (in Shared\EditorTemplates\Date.spark and using SparkViewEngine):

<viewdata model="DateTime" />
${Html.TextBox("", string.Format("{0:d}", Model.ToShortDateString()), new { id = "", @class = "datepicker" })}

View:

<p>
    <label for="ProcessDate">
        Date
        <small>
            <span class="error">${Html.ValidationMessageFor(m => m.ReportDate)}</span>
        </small>
    </label>
    ${Html.EditorFor(m => m.ReportDate, "Date")}
</p>

Action:

public ActionResult StatementsReport(DateTime? reportDate)
{
    if (!reportDate.HasValue)
        reportDate = DateTime.Now;

    var report = new ReportModel { ReportDate = reportDate.Value.Date };
    return View("Statements/GenerateReport", report);
}

If I need to provide more detail, please let me know.

Any help greatly 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-06-06T15:36:39+00:00Added an answer on June 6, 2026 at 3:36 pm

    The default model binder uses InvariantCulture with GET requests and the thread culture for POST requests when parsing. This basically means that if you are passing your reportDate action parameter in a GET request (as a query string parameter) you must use InvariantCulture to format it. Ideally use:

    some_url?reportDate=yyyy-MM-dd
    

    If you are sending a POST request (a.k.a submitting the form containing the input field), then the date must be formatted according to your application culture because this is what the model binder will use.

    Checkout the following blog post which illustrates this.

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

Sidebar

Related Questions

I have this Editor Template so that I have a datepicker set for date
I currently have a display template for DateTime? objects that corrects the date depending
I have page where I use model which can have different types (depending by
I have page named page--news.tpl.php, which i created for my news page. But after
I have page (Default1.aspx) in which I am redirecting to another page (Default2.aspx) using
I have page which is redirected from htaccess. now I can pass the German
I have Page Tab App, which has a landing page with a Log In
I have a web page that uses a date range filter, the selected date
I am building a web app with jquery mobile. On one page I have
Say you have a xaml page that takes two inputs such as DATE and

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.