-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);
    }
Tom
  • 8,175
  • 41
  • 136
  • 267

1 Answers1

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.

Craig H
  • 2,001
  • 1
  • 14
  • 18
  • I get the message MessageDetail": "No action was found on the controller 'Terms' that matches the name '5508'. – Tom May 09 '19 at 15:35
  • 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 – Tom May 09 '19 at 15:40
  • This sounds like you are trying to use attribute routing, but maybe haven't enabled it and traditional convention routing is kicking in. – Craig H May 09 '19 at 15:40
  • Could be. Not sure how to fix this – Tom May 09 '19 at 15:44