ASP.NET Web API - ModelBinders

前端 未结 4 418
渐次进展
渐次进展 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:58

    I think you don't need a model binder. Your approach is incorrect. The right approach for dates is using a client side globalization library like the globalize library to parse dates formatted in any language and transform them into JavaScript date objects. Then you can serialize your datascript data structures in JSON with the browser JSON.stringify, and this should work. It is better to use always standard formats for dates and to use a formatter instead than a model binder. Available formatters handle also TimeZones correctly, if you use the kind parameter of your C# DateTime objects to specify if the date time is expressed in local time or in UTC time.

提交回复
热议问题