使用JSON对象请求WebApi DateTime Post?

时间:2017-05-11 07:33:47

标签: c# datetime asp.net-web-api

   public object postDate(DateTime start)
    {
      //Save the DateTime to sql Server
      //return success code or object

    }

json字符串如何发布DateTime?

1 个答案:

答案 0 :(得分:0)

创建一个对象并将其包装为:

Public class SampleModel
{
    Public DateTime Start {get; set;}
}

然后将其发布到Action:

 public object postDate(SampleModel sampleModel)
{
  // sampleModel.Start
  //Save the DateTime to sql Server
  //return success code or object

}

JSON必须是这样的:

 {
  "Start":"2017-05-11T09:18:54.092Z"
 }