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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:15:43+00:00 2026-05-13T10:15:43+00:00

I have a search form with a DateTime search criterion, plus some other criteria:

  • 0

I have a search form with a DateTime search criterion, plus some other criteria:

<form method="get" action="/app/search">
    <input type="text" value="13/01/2010" name="BeginDate"/>
    <input type="text" value="blah" name="SomeOtherCriterion"/>
<form>

So I have a Search controller with a default Action (let’s call it Index) and with a SearchCriteria parameter.

public class SearchController
{
    public ActionResult Index(SearchCriteria searchCriteria) {//blah }
}    

public class SearchCriteria
{
    public DateTime BeginDate {get; set;}
    public string SomeOtherCriterion {get; set;}
}

Now if I want to create an ActionLink, passing in a SearchCriteria value, thus:

Html.ActionLink("Search", "Index", searchCriteria)

I get the BeginDate query string parameter in US format. Looking on Google and poking around in System.Web.Routing using Reflector it seems to be because it uses the InvariantCulture, so there’s nothing I can do about it.

It seems like noone has asked this question before so I guess I’m doing something very stupid…. Please help!

EDIT: Pass in SearchCriteria to ActionLink rather than anonymous object to show why I can’t just do the custom ToString() myself.

  • 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-13T10:15:44+00:00Added an answer on May 13, 2026 at 10:15 am

    Given that the framework appears to be hard-coded to handle this piece of data using InvariantCulture, I don’t think there’s much you can do to make it work transparently.

    There is one ugly option – download the MVC source and rip out the code for all the offending classes from Route down to ParsedRoute to create your own RouteBase implementation that does what you need.

    If I absolutely had to keep the DateTime declaration on the SearchCriteria class, then that’s the route (sorry for the pun) I would choose.

    However, a far easier solution would be to change your SearchCriteria class to use a slightly different declaration for the DateTime field, based on a type like this:

    public class MyDateTime
    {
      public DateTime Value { get; set; }
      //for passing MyDateTime in place of a DateTime without casting
      public static implicit operator DateTime(MyDateTime instance) { return instance.Value; }
      //so you can assign a MyDateTime from a DateTime without a cast
      //- e.g. MyDateTime dt = DateTime.Now
      public static implicit operator MyDateTime(DateTime instance) { return new MyDateTime() { Value = instance }; }
      //override ToString so that CultureInfo.CurrentCulture is used correctly.
      public override string ToString()
      {
        return Value.ToString(CultureInfo.CurrentUICulture);
      }
    }
    

    In theory you should be able to roll out this change without too much fuss.

    The big work could be if you have a lot of code that uses members (e.g. .Days etc) of the DateTime instance in SearchCriteria: you either have to reproduce those members on MyDateTime, wrapping around the inner DateTime Value or change all the code to use .Value.Member.

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

Sidebar

Related Questions

Ok so i have a form <form action=/search method=post> <input type=hidden name=location_id value=1 /><br
I have a search form <form id=search method=GET> <input type=text name=q id=q /> <input
I have a search form in an app I'm currently developing, and I would
I have a simple search form with a box and a button. <form action
I have a search form with inputs and selects, and when any input/select is
I have a search form: <form id=global_search> <input id=global_search_input name=search_query placeholder=Enter search text> <input
I have a search form regarding property search having some elements on which search
I have a search form on which I have the following INPUT field <input
I have a search query form on my home page (/) <% form_tag(search_path, :method
I have a search form with a query builder. The builder is activated by

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.