1
I am creating a web Api project and wanted to put a set of methods in the same Controllerapi.
But in the methods, I pass a Json object as a parameter. And as their structure looks similar (see example), the controller gets confused because he thinks they are all the same and so always calls the first method.
How can I fix this ?
Thanks in advance
Example:
public class MeuController : ApiCOntroller
{
public List<Series> ObterSeries (ParametroSeries parametros)
{ ... }
public List<Contas> ObterContas (ParametroContas parametros)
{ ... }
}
The call is being made as follows:
$.post("api/MeuController/ObterContas", { Identificacao: '12.234.567/0001-89' })
.done(function (data) { ... })
});
$.post("api/MeuController/ObterSeries", { Identificacao: '12.234.567/0001-89' })
.done(function (data) { ... })
});
Obs: Used json because there are other parameters that may or may not be informed
Place the code where you are passing JSON, to see what the problem is.
– Tony
And add the language tag you are using. Just click [Edit] below the question.
– brasofilo
How are the route settings on Webapiconfig.Cs?
– Leandro Godoy Rosa
config.Routes.Maphttproute( name: "Defaultapi", routeTemplate: "api/{controller}/{id}", defaults: new { id = Routeparameter.Optional } ); config.Routes.Maphttproute( name: "Meuapi", routeTemplate: "api/{controller}/{action}/{parameters}" );
– Rogério Calixto