user1531040
user1531040

Reputation: 2301

How to hit a HttpPost-action with a parameter?

I have an API with a

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

and when I wanna calling this Action

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

then i will come in the Action of the API.

... and when you add something like this

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

then we did not comein the Action of the API.

How can I solve this problem?

Upvotes: 2

Views: 641

Answers (1)

Nemanja Todorovic
Nemanja Todorovic

Reputation: 2820

You can change your endpoint like this:

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

also, make sure that you are passing correct guid.

Upvotes: 3

Related Questions