1
votes

I have this method:

    [HttpPost]
    [Route("Post")]
    public async Task<IHttpActionResult> Post(int adminTestId)

I am sending the following but it's giving me an error:

POST /api/UserTest/Post

    body {"adminTestId":1197}

Can someone tell me how I can set the parameter to the method so it will accept adminTestId?

Here is the message that I am getting:

{"message":"No HTTP resource was found that matches the request URI 'http://localhost:3048/api/UserTest/Post'.","messageDetail":"No action was found on the controller 'UserTest' that matches the request."}

2

2 Answers

1
votes

I believe you are setting the incorrect route:

[Route("UsetTest/Post")]

This is assuming api/ is the correct prefix.

0
votes

In Web API, requests are mapped to actions based on HTTP verbs.

Therefore, you should not include Post in your URL which defeats the purpose of using Web API and violate REST rules.

Post Json

If you want to post json, you want to bind to a model.

enter image description here

enter image description here

Post Integer

If you just want to accept an single integer value, you just post an integer instead of json.

enter image description here

enter image description here