Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>There is one ugly option - download the MVC source and rip out the code for all the offending classes from <code>Route</code> down to <code>ParsedRoute</code> to create your own <code>RouteBase</code> implementation that does what you need.</p> <p>If I absolutely <i>had</i> to keep the DateTime declaration on the <code>SearchCriteria</code> class, then that's the route (sorry for the pun) I would choose.</p> <p>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:</p> <pre><code>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); } } </code></pre> <p>In theory you should be able to roll out this change without too much fuss.</p> <p>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 <code>MyDateTime</code>, wrapping around the inner <code>DateTime Value</code> or change all the code to use <code>.Value.Member</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload