-1

I have written asp.net web.api method that accepts two parameters. It doesnt hit the web method when I call the method from postman. It works fine when I define the method to accept one parameter and call with one parameter but doesnt call when i define it with two parameters and call with two parameters

 [HttpGet] [Route("api/terms/{id}/{invested}")] public IHttpActionResult Details(int id, bool invested) { var viewModel = GetTermsViewModel(id, invested); if (viewModel == null) return NotFound(); return Ok(viewModel); } 
4

1 Answer 1

0

You do not need to specify /details/ in your incoming request URL.
The URL you should be calling is

/api/terms/5508/true 

Edit from comment:

To enable attribute routing, go to the Register method in your WebApiConfig class and add this:

config.MapHttpAttributeRoutes(); 

Read about attribute routing here.

Sign up to request clarification or add additional context in comments.

4 Comments

I get the message MessageDetail": "No action was found on the controller 'Terms' that matches the name '5508'.
As I mentioned earlier the the method hits if i just set the parameter to id and call it with id value. localhost:56888/api/terms/details/5508
This sounds like you are trying to use attribute routing, but maybe haven't enabled it and traditional convention routing is kicking in.
Could be. Not sure how to fix this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.