How to receive object json with Web Api 2. I send the object correctly, but in the backend my object is null. See below.
My object JSON
This is my JSON object that will be sent in the request.
{
"ItensRateio" : [
{
"TipoColetorCusto" : "1",
"ColetorCusto" : "MRBHAD",
"Valor": "R$ 25.22",
"Descricao": "Rateio do Brasil"
},
{
"TipoColetorCusto" : "1",
"ColetorCusto" : "MRBHAD",
"Valor": "R$ 25.22",
"Descricao": "Rateio do Brasil"
}
]
}
My object.
This is my mapped object. A class that needs to be populated with the JSON object that is received in the request.
public class RateioSimplesRequestModel
{
List<ItemRateio> ItensRateio { get; set; }
List<ItemMaterial> ItensMaterial { get; set; }
public RateioSimplesRequestModel()
{
ItensRateio = new List<ItemRateio>();
ItensMaterial = new List<ItemMaterial>();
}
}
public class ItemRateio
{
public string TipoColetorCusto { get; set; }
public string ColetorCusto { get; set; }
public string Valor { get; set; }
public string Descricao { get; set; }
}
public class ItemMaterial
{
public string CNAE { get; set; }
public string CodigoMaterial { get; set; }
public string Descricao { get; set; }
}
My method in the WebAPi 2
[Route("CalcularRateioManual")]
[HttpPost]
public RespostaPadrao<bool> CalcularRateioManual([FromBody] RateioSimplesRequestModel parametro) // THIS OBJECT
{
RespostaPadrao<bool> retorno = new RespostaPadrao<bool>();
return retorno;
}
How I can this be perfectly?
