For about 6 months I've been entering the MVC world, before I've used a lot of WebForms and I confess that I'm having trouble understanding how to configure the routes for a ApiController
, so I noticed I can not have two equal queries (with the same parameters), but I'm a bit clumsy to set this up.
Below I will put an example code that is giving the error below when trying to access them.
{
"Message":"No HTTP resource was found that matches the request URI 'http://localhost:54596/api/graficos/usuarios/'.",
"MessageDetail":"No action was found on the controller 'Graficos' that matches the name 'usuarios'."
}
GraphicsController
public class GraficosController : ApiController
{
[HttpGet]
//[Route("api/graficos/usuarios/{action}/{param}")]
public List<UsuarioDashboard> BuscaUsuarioDashboard(string param)
{
return Fachada.FachadaEstatisticas.BuscaUsuarioDashboard(param);
}
[HttpGet]
//[Route("api/graficos/emails/{action}/{param}")]
public List<EmailNaoEnviado> EmailsNaoEnviados(string data)
{
return Fachada.FachadaEstatisticas.EmailsNaoEnviados(Convert.ToDateTime(data));
}
}
In Global.asax I'm doing the route as follows:
RouteTable.Routes.MapHttpRoute(
name: "Site",
routeTemplate: "api/{Controller}/{action}/{site}",
defaults: new { }
);
RouteTable.Routes.MapHttpRoute(
name: "Usuarios",
routeTemplate: "api/{controller}/{action}/{param}",
defaults: new { }
);
RouteTable.Routes.MapHttpRoute(
name: "Graficos",
routeTemplate: "api/{controller}/{action}",
defaults: new { }
);
I think my mistake is trying to use the same controller for more than one function. Is that it?
I have already researched several sites, but I have not found any that have an explanation that I understand.