.NET Core 1.0.0 POST FromBody请求始终为null。

时间:2017-01-26 16:40:09

标签: .net asp.net-web-api asp.net-core

我的新POST端点始终为请求变为null,我无法弄清楚原因。

// api/StudentQueue/Comment
[HttpPost]
    [Route("Comment")]
    public async Task<IActionResult> PostStudentComment([FromBody]StudentQueueNewCommentModel model)
    {
        // stuff
    }

这是那个模型:

public class StudentQueueNewCommentModel
{
    public StudentQueueCommentModel Comment { get; set; }
    public StudentQueueModel Student{ get; set; }
}

这是我的有效载荷:

{
  "Comment": {
    "ActionId": 2,
    "ActionName": "Contacted – Student Responded",
    "Comment": "jhgfd",
    "CreatedDate": "Thu Jan 26 2017 11:14:17 GMT-0500 (Eastern Standard Time)",
    "CreatorName": "TODO: Figure this out"
  },
  "Student": {
    "Id": 1,
    "FirstName": "Inquisitive",
    "Lastname": "Seal",
    "Email": "iseal@mailinator.com",
    "PhoneNumber": "(555) 555-5555",
    "Comments": [
      {
        "createdDate": "2016-10-19T00:00:00",
        "comment": "Comment 1",
        "actionId": 1,
        "actionName": "Contacted – Waiting for Response",
        "creatorName": "Bobby Ross"
      },
      {
        "createdDate": "2016-10-19T00:00:00",
        "comment": "Comment 2",
        "actionId": 2,
        "actionName": "Contacted – Student Responded",
        "creatorName": "Lil Drop Tables"
      }
    ]
  }
}

我有content-typeapplication/json,但我在API方法的第一行设置了一个断点,并且每次都没有失败。

我尝试将有效负载包装在{model: everythingabove}中,控制器中的Student为我提供了一个模型对象,Comment.Find()为空。我完全不知道这里发生了什么。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

想出来。它不喜欢我的日期格式(当然合理)。我最终没有发送日期,因为我希望它无论如何都要设置为服务器端。