2

我有一个 API

[HttpPost("InsertSomething")]
public async Task<IActionResult> InsertSomething(Guid id, [FromBody] MyModel model)
{
   try
   {
      ...
      Guid somethingId = await _myService.Insert(id, enz..)

当我想调用这个动作时

HttpResponseMessage result = await client.PostAsync("/MyContr/InsertSomething", content);

然后我将进入 API 的 Action。

...当你添加这样的东西时

HttpResponseMessage result = await client.PostAsync($"/MyContr/InsertSomething?id=BlaBlaBla", content);

然后我们没有进来API的Action。

我怎么解决这个问题?

4

1 回答 1

3

您可以像这样更改端点:

 [HttpPost("InsertSomething")]
 public async Task<IActionResult> InsertSomething([FromQuery]Guid id, [FromBody] MyModel model)

另外,请确保您传递了正确的 guid。

于 2021-06-23T21:03:43.100 回答