I get that error when trying to access the route defined in my controller
which is in a post method that sends and receives parameters as indicated in the following code:
[HttpPost]
[Route("api/ConsultasGP/ConsultasPuertos")]
public async Task<IList<PuertosGP>> ConsultasPuertos([FromUri]string id,
[FromBody] List<PuertosGP> lstPuertosGP, [FromUri]DateTime fecha)
{ ..... demas codigo
When doing a test in POSTMAN, the following message appears: "No HTTP resource was found that matches the URI of the request " http://localhost:24175/api/ConsultasGP/ConsultasPuertos "
In my WebApiConfig.cs it is configured in this way:
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Could you explain to me what is the mistake I am making?
I don't understand what the error is.
UPDATE I missed adding the [FromUri] and [FromBody] since this requires sending the Id which is a string
You must indicate in the route that you have defined for the Action
ConsultasPuertos(...)
, the parameters that will come from the Url (id
andfecha
):And on the other hand, in the route configuration, indicate these parameters as optional: