Here I'm Trying to implement multiple Get methods but the browser througs an error Multiple actions were found that match the request
. Why does this happen?
In the Api Controller I added two methods: 1. GetEmployee 2. HelloDept If I comment out one of them it's working fine.
public class TrailController : ApiController
{
private IProduct Repo = new Product();
[HttpGet]
public IEnumerable<Employee> GetEmployee()
{
var x = Repo.GetEmp();
return x;
}
[HttpGet]
public IEnumerable<Department> HelloDept()
{
var x = Repo.GetDept();
return x;
}
RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{api}/{controller}/{action}/{id}",
// defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
defaults: new {id = RouteParameter.Optional }
);