JSON 值无法转换为 System.DateTime

The JSON value could not be converted to System.DateTime

我有一个 员工 table

public class Employee
{
   [Key]
   public long ID { get; set; }
   public DateTime EmpDate { get; set; }
   public string FirstName { get; set; }
   public string LastName { get; set; }
}

我已经为 post 员工数据创建了网站 API:

[HttpPost]
public async Task<ActionResult<Employee>> PostLead(Employee employee)
{
      //Code to post
}

这是我的JSONbody

{
    "firstname":"xyz",
    "lastname":"abc",
    "EmpDate":"2019-01-06 17:16:40"
}

我收到错误 The JSON value could not be converted to System.DateTime. 但是当我将 EmpDate 值作为 2019-01-06 传递时,我没有收到错误。

您 JSON 中的日期值不正确。应该是

2019-01-06T17:16:40

大多数解析器使用 ISO 8601