I am new to the WebAPI and I got stuck in a problem. I am using API controller which contains two Get
methods. One is used for GetAll
while other retrieves data on the basis of ID. Now what I want to do is to implement another get method which takes string
and returns records. I have made that method and call that it does not work as my route was default API route which was like:
config.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
When I added a new route to call my custom GetMethod
:
config.Routes.MapHttpRoute(name: "Custom", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } );
I was able to call my custom GetMethod
but now I lose the restful method with id parameters. How can I use both methods?