A day with .Net

My day to day experince in .net

Posts Tagged ‘Multiple actions were found that match the request’

Multiple Get methods in Web API controller -Ninject.

Posted by vivekcek on September 28, 2013

When you have multiple get methods in a web api controller like below.

    public class WebApiController : ApiController
    {
        private IMyInterface _iMyInterface = null;

        public WebApiController(IMyInterface iMyInterface)
        {
            _iMyInterface = iMyInterface;
        }

        [HttpGet]
        public string GetName()
        {
            return _iMyInterface.Name;
        }

        [HttpGet]
        public string GetTest()
        {
            return _iMyInterface.Name;
        }
    }

Then you try to call ‘http://localhost:58956/api/WebApi/GetName‘ you may get an error like.

“ExceptionMessage”:”Multiple actions were found that match the request:

8

This is a simple route issue.The default route setting in WebApiConfig is shown below.

9

Change the above to.

10

Posted in MVC | Tagged: , | Leave a Comment »