Handling dates with Asp.Net MVC and KnockoutJS

前端 未结 8 1211
滥情空心
滥情空心 2020-12-08 04:56

I recently started working with KnockoutJs and quickly realized using the default Json(myModelWithADate) resulted in the default json encoding of \\/Date(

8条回答
  •  眼角桃花
    2020-12-08 05:05

    A cleaner alternative to @photo_tom's answer is to decorate the property with the IsoDateTimeConverter via the JsonConverter attribute, like so:

    public class MyClass
    {
        [JsonConverter(typeof(IsoDateTimeConverter))]
        public DateTime Timestamp { get; set; }
    }
    

提交回复
热议问题