1
When you Get using Ajax, viewModel is coming to the Controller with the fields reset. I’m creating the class manually, converting it and doing the GET. I cannot figure out the reason for the problem, whether I am "setting" the fields with values in wrong format or if there is a problem doing the stringfy. I have tried several ways and could not solve. Someone would know how to help me?
Thank you and a hug to all!
Viewmodel:
public class FinanceiroParcelaMovimentoCalculosPadraoViewModel
{
public decimal ValorASerPago { get; set; }
public decimal ValorPago { get; set; }
public decimal PercentualJuros { get; set; }
public decimal PercentualMulta { get; set; }
public decimal PercentualDesconto { get; set; }
}
Controller:
[HttpGet]
[Route("financeiro-parcela-movimento-gerenciar/financeiro-parcela-movimento-calcular-valores-padrao")]
public JsonResult CalcularValoresPadrao(FinanceiroParcelaMovimentoCalculosPadraoViewModel financeiroParcelaMovimentoCalculosPadraoViewModel)
{
return Json(new { financeiroParcelaMovimentoCalculosPadraoViewModel = financeiroParcelaMovimentoCalculosPadraoViewModel });
}
JS:
var valorASerPago = $("#txt-financeiro-parcela-movimento-valor-a-ser-pago").val();
var valorpago = $("#txt-financeiro-parcela-movimento-valor-pago").val();
var financeiroParcelaMovimentoCalculosPadraoViewModel = {
ValorASerPago: valorASerPago ? parseFloat(valorASerPago.replace(',', '.')) : 0,
ValorPago: 0,
PercentualJuros: 0,
PercentualMulta: 0,
PercentualDesconto: 0,
};
$.ajax({
url: "/financeiro-parcela-movimento-gerenciar/financeiro-parcela-movimento-calcular-valores-padrao",
type: "GET",
data: JSON.stringify(financeiroParcelaMovimentoCalculosPadraoViewModel),
traditional: true,
success: function (data) {
},
error: function () {
stopLoadGlobal();
alert("Oops! Algo deu errado.");
return false;
}
});