I don´t know why my parameter “ParametroFiltro Filtro” is getting null, the other parameters “page” and “pageSize” is getting OK.
public class ParametroFiltro
{
public string Codigo { get; set; }
public string Descricao { get; set; }
}
My ApiController Get method:
public PagedDataModel<ParametroDTO> Get(ParametroFiltro Filtro, int page, int pageSize)
My ajax call:
var fullUrl = "/api/" + self.Api;
$.ajax({
url: fullUrl,
type: 'GET',
dataType: 'json',
data: { Filtro: { Codigo: '_1', Descricao: 'TESTE' }, page: 1, pageSize: 10 },
success: function (result) {
alert(result.Data.length);
self.Parametros(result.Data);
}
});
You are trying to send a complex object with
GETmethod. The reason this is failing is thatGETmethod can’t have a body and all the values are being encoded into the URL. You can make this work by using[FromUri], but first you need to change your client side code:This way
[FromUri]will be able to pick up your complex object properties directly from the URL if you change your action method like this:Your previous approach would rather work with
POSTmethod which can have a body (but you would still need to useJSON.stringify()to format body as JSON).