27
我正在使用帶有屬性路由的ASP.NET Web API 2。在POSTMAN Rest Client中的Web API 2 POST請求模擬
我有以下PlayerModel
。
public class PlayerModel
{
public int Id { get; set; }
public string Key { get; set; }
public string Name { get; set; }
public string Password { get; set; }
public int TeamId { get; set; }
public PlayerStatModel Stat{ get; set; }
}
public class PlayerStatModel
{
public int PlayerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public string EmailAddress { get; set; }
public IEnumerable<PhoneNumberModel> PhoneNumbers { get; set; }
public int TeamId { get; set; }
}
public class PhoneNumberModel
{
public string Value { get; set; }
public string Extension { get; set; }
}
這反過來又傳遞到PostPlayer
供玩家創造。
[HttpPost("", RouteName = "PostPlayer")]
public PlayerModel PostPlayer(PlayerModel player)
{
var playerObject = this.GetObject(player));
this._manager.CreatePlayer(playerObject);
return this.GetPlayer(playerObject.Id);
}
我的集成測試通過,我能夠來驗證播放器時被調用CreatePlayer
確實創建。
如何在Google Chrome中的POSTMAN Rest Client中爲此POST
請求建模?
你們能不能進一步解釋我面臨的問題很少。 – NomanJaved
在ASP.net核心中添加[FromBody]標籤前面的參數。 – Prageeth