服务堆栈:如何使用jQuery发布DateTime

时间:2013-01-17 18:34:59

标签: servicestack

假设我有一个如下所示的请求DTO:

public class MyRequest
{
    public DateTime? SomeDateTime { get; set; }
}

在客户端上我想使用jQuery发布它:

$.ajax({
    type: 'POST',
    url : '/myrequest',
    data: { someDateTime: new Date() },
    dataType: 'json',
    success: function (data) { console.log(data.success); }
});

为什么有效?永远不会填充MyRequest.SomeDateTime。我应该通过什么而不是new Date()

1 个答案:

答案 0 :(得分:1)

传递

new Date().toJSON()

有关json中日期的更多信息,请参阅The "right" JSON date format