Binding en-GB dates in a HTTP GET

前端 未结 2 541
无人共我
无人共我 2020-12-09 21:30

I\'m having a nightmare of a time with Dates. Were based in the UK, so our date format is dd/MM/yyyy. This is what users will type into the form when they want a certain dat

2条回答
  •  一向
    一向 (楼主)
    2020-12-09 21:57

    In addition to Liam's answer:

    For those who are still having this issue (!) and are trying to bind to a Nullable DateTime, make sure you register the correct type in global.asax:

    ModelBinders.Binders.Add(typeof(DateTime), new GBDateModelBinder());
    ModelBinders.Binders.Add(typeof(DateTime?), new GBDateModelBinder());
    

    Had me stumped for 15 minutes!

提交回复
热议问题