I know there are already such questions, but the context there is very different probably because of the older .NET MVC versions.
I am getting the error No type was found that matches the controller named 'employee' when hitting the route "/api/employee/5" on the localhost. The entire route is like "127.0.0.1:8080/api/employee/5". The home route at "127.0.0.1:8080" works as expected.
I have configured the route in my controller.
EmployeeController.cs
[Route("api/employee")]
public class EmployeeApiController : Controller
{
[HttpGet, Route("api/employee/{id}")]
public ActionResult GetEmployee(long id)
{
return Content(
new Employee("Bobby", "Smedley",
"London", "Teheran",
EmployeeGender.M,
DepartmentCode.D_2157020,
"12345678901").ToString(),
"application/json");
}
}
I made no changes to the WebApiConfig.cs and it looks like follows.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Does anyone know what is the issue with that?