Ajax - Float Parameter

0

Hello, I need ajax help, I think it's a silly thing, but I'm having a hard time and I did not find anything related on the internet about it, I need to pass ajax parameter to my controller, but float type, I created a json object to try to get the value float type, but neither with object nor with explicit value I can pass type float, just string and type int.

I'm using ajax function, where I create an object and send values, being vlTotalLiquido, vlUnitario, are values of type float because it is money, but in that part I disregard why jquery is not a typed language but the value is sure as I want to send, EXAMPLE: 2.00

var Objeto = new Object();
        Objeto.idProduto = idProduto;
        Objeto.IdPreVenda = parseInt($("#idPreVenda").val());
        Objeto.qtItem = parseInt($("#qtItem").val());
        Objeto.vlUnitario = parseFloat($("#vlUnitario").val());
        Objeto.prDesconto = parseFloat($("#prDesconto").val());
        Objeto.vlTotalLiquido = parseFloat($("#ValorComDesconto").val());    


$.ajax(
{

    url: "/ItPreVenda/SalvarItens",
    dataType: "json",
    type: "POST",
    data: Objeto,
    success: function (data) {
        if (data.Resultado > 0)
            alert('sucesso');
            ListarItens(idprevenda);
    }
});

Below is the code of my controller, I am getting all INT values in my Object but the float values I can not receive!

 [HttpPost]
        public ActionResult SalvarItens(ItPreVenda Objeto)
        {
            //ainda irei tratar os valores
            return Json(Objeto);
        }

If someone knows a way to do it, thank you, THANK YOU and A HAPPY NEW YEAR TO ALL!

    
asked by anonymous 28.12.2015 / 12:46

1 answer

0

In fact, everything you put in JSON technically ends up turning a string that will be passed to your controller.

So the only thing you need to do is to convert this string to float on your backend.

    
28.12.2015 / 12:53