1

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

1 Answer 1

4

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.