【发布时间】:2023-02-03 10:55:11
【问题描述】:
我试图从 POST 控制器中的请求主体获取一些数据,但控制台显示空道具:
邮政控制器:
[HttpPost("{id}/features")]
public ActionResult<bool> AddFeatureAsync(Guid Id, [FromBody] AddRoleFeatureRequest request)
{
Console.WriteLine(request.Name);
Console.WriteLine(request.Description);
Console.WriteLine(request.Id);
return true;
}
AddRoleFeatureRequest 类:
public class AddRoleFeatureRequest
{
public Guid Id;
public string? Name;
public string? Description;
}
来自 Postman 的 JSON 数据(使用 body raw 作为 Json):
{
"name": "Feature ABC",
"description": "description",
"id": "7e12b0ad-2c82-46f0-a69e-8538efb0aa60"
}
我究竟做错了什么?
【问题讨论】:
-
您的 Postman curl 命令语句是什么?
-
你没有任何道具。我只看到字段:尝试添加
{ get; set; } -
可以肯定的是,您是否在 Postman 中设置了
Content-Type: application/json标头?
标签: c# asp.net-core