I have two Get methods. I want to access this by using following urls

But I am trying to call this I am getting following exception

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

     // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(SomeEnum id)
        {
           //somecode
            return "value";
        }

        [HttpGet("{id}")]
        public ActionResult<string> Get(SomeEnum id,int status)
        {


//somecode
            return "value";
        }

Is there any way to use routs like this with mutltiple get methods

1 Answers

0
user10103607 On

There is nothing out of the box provided by ASP.NET core to help your case. As suggested in one of the comments, you should make the status parameter as nullable and use it within the action method to decide what next to do. Something like this:

[HttpGet("{id}")]
public ActionResult<string> Get(SomeEnum id,int? status)
{
    if(status == null)
    {    
        //perform usual logic which requires only id
    }
    else
    {
        //perform logic or call a method which requires both id and status
    }
    return "value";
}