ASP.NET Web API - ModelBinders

前端 未结 4 412
渐次进展
渐次进展 2021-01-08 01:13

I need to use a custom modelbinder of some kind to always treat incoming dates in UK format, i have setup a custom model binder and registered like so:

Globa         


        
4条回答
  •  暖寄归人
    2021-01-08 01:45

    You do not need a custom model binder for that. You should be good by changing the thread culture to UK or set your web.config settings for UK, if this is what your site is using all the time.

    If not, you can still change the DateTimeFormatInfo for the CurrentCulture to UK one.

    There is also a good post about model binders available here by Scott Hanselman.

    You can put this in Global.asax:

    ModelBinders.Binders[typeof(DateTime)] = new DateAndTimeModelBinder()  
    

提交回复
热议问题