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?
try this
but if it is possible change controller name to CompaniesController. In this case you will not need an attribute routing