Click here to Skip to main content
14,836,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Controller:
public class testADOController : ApiController
   {
       [HttpGet]
       public testOrg GetOrgTreeStr(int emp_no)
       {
            return testadoBL.GetTestOrg(emp_no);
       }
   }



WEbAPiCOnfig.cs file data:

config.MapHttpAttributeRoutes();

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



ROute config file data:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}



my API call:
somelocalhost/api/testado/GetOrgTreeStr/100100


Error:
{
Message: "No HTTP resource was found that matches the request URI 'http://localhost:53435/api/testado/GetOrgTreeStr/100100'.",
MessageDetail: "No action was found on the controller 'testADO' that matches the request.",
}


What I have tried:

http://localhost:53435/api/testado/GetOrgTreeStr/100100[^]

http://localhost:53435/api/testado/GetOrgTreeStr?=100100[^]
Posted
Updated 30-Oct-20 7:25am

1 solution

In your route, the parameter is called id.

In your method, the parameter is called emp_no.

Either change your method parameter name:
C#
public testOrg GetOrgTreeStr(int id)
or pass the value in the querystring:
somelocalhost/api/testado/GetOrgTreeStr?emp_no=100100
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900