c# - Control dateformat when using Url.action or similar -
i aware of problems putting dates in querystring , way ignore globalisation in instance. use standard uk format dd/mm/yyyy in places in app - have <globalization uiculture="en-gb" culture="en-gb" />
set in web.config, , use custom modelbinder make sure posted dates parse when using uk format. having cribbed melvyn harbour - mvc modelbinder , localization
i have read number of posts suggesting setting format yyyy-mm-dd when passing dates in url, sounds plan. problem how set when calling url.action this:
urlhelper.action(actionname, controllername, filteringoptions);
where filteringoptions class datetime
properties within thus:
public class filteringoptions{ public string searchterm{get;set;} public datetime? fromdate{get;set;} public datetime? todate{get;set;} public int? brandid {get;set;} //...etc }
i know last parameter in url.action call above, gets stuck in routevaluedictionary
, here datetime
properties go wonky, reverting date format rather uk had been dealing - of course makes fall on when parsing date doesn't work both ways, or worse, swaps day , month numbers on causing other mayhem.
i more happy have dates passed using yyyy-mm-dd format, but how make sure format used? - without having loop around properties in class , calling tostring("yyyy-mm-dd") on date ones.
any appreciated
you can change system date format, make work perfectly.
Comments
Post a Comment