2
I have a search method in my Webapi, as it is a search, I used [HttpGet]
, as a parameter of this method, I pass an object with the filter options I want, for example:
public class ParametrosBusca {
public string nome { get; set; }
public DateTime dataInicial { get; set; }
public DateTime dataFinal { get; set; }
}
The declaration of the method:
[HttpGet]
public JsonResult Buscar(ParametrosBusca parametros) {
//...//
}
When calling my Api by passing the parameter, my object is not deserialized, however, if I change the method to receive the string type parameter I receive it correctly and can deserialize it correctly, this way:
[HttpGet]
public JsonResult Buscar (string parametros) {
var teste = new JavaScriptSerializer().Deserialize<ParametrosBusca>(parametros);
//...//
}
In case I use [HttpPost]
, my parameter is also deserialized correctly.
My question, can’t pass complex objects in methods like HttpGet
?
Show.. Thank you for the reply.
– Pedro Camara Junior
@merchant has some advantage in using [Fromuri] no get instead of making a post?
– Aesir
@Aesir I would not say that there is advantage or disadvantage, but rather that it is important to maintain the consistency of the objective of the requests.
GET
is recommended to receive data from the server, whilePOST
is used to send information in order to make it persistent.– mercador