0

I have ApiController that looks like

[RoutePrefix("Companies")]
public class CompanyController : ApiController
{
  [HttpGet]
  [Route("GetCompanyProfile")]
  public GetProfileOutput GetCompanyProfile()
  {
     // some code
  }
}

Now, if I try to simplify the code so that I dont have to specify the route name explicitely, but instead reuse the action function name, it looks like this:

[RoutePrefix("Companies")]
public class CompanyController : ApiController
{
  [Route, HttpGet]
  public GetProfileOutput GetCompanyProfile()
  {
     // some code
  }
}

But now, the GetCompanyProfile action is not any longer recognized.

What is my code actually doing? Is there a way to have the route name automatically fetched from the action name?

Anders Lindén
  • 6,839
  • 11
  • 56
  • 109

1 Answers1

0

try this

[Route("Companies/[action]")]
public class CompanyController : ApiController
{
   public GetProfileOutput GetCompanyProfile()
  {
     // some code
  }
}

but if it is possible change controller name to CompaniesController. In this case you will not need an attribute routing

Serge
  • 40,935
  • 4
  • 18
  • 45