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 method declaration:
[HttpGet]
public JsonResult Buscar(ParametrosBusca parametros) {
//...//
}
When calling my Api, passing the parameter, my object is not deserialized, but its I change the method to receive the parameter of type string I get it correctly and I can deserialize correctly, like this:
[HttpGet]
public JsonResult Buscar (string parametros) {
var teste = new JavaScriptSerializer().Deserialize<ParametrosBusca>(parametros);
//...//
}
If I use [HttpPost]
, my parameter is also deserialized correctly.
My question, can not I pass complex objects in methods of type HttpGet
?