Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following code in my WebApiConfig.cs

   config.Routes.MapHttpRoute(
        name: "Action",
        routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { id = RouteParameter.Optional }
   );

ABCController.cs

 public class ABCController : ApiController
 {        
     [AcceptVerbs("GET")]
     [ActionName("GetABCByXYZById")]
     public string GetABCByXYZById(int xYZId)
     {                
         return "GetABCByXYZById";
     }
 }

When I try to call the API it says not able to find the action in the controller.

 /api/ABC/GetABCByXYZById/12
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

It's because your routeTemplate uses the name {id} for the action parameter but your action actually takes in a parameter with name xYZId.

Try changing your action parameter to called id and it should work:
public string GetABCByXYZById(int id)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.