JsonResult request with decimal type

1

Because when I send a request with a decimal type (3) the "Point" is deleted, see in the INSS field which is a decimal value, for example: I type 1,69 when doing a bind in the model the point is eliminated and transformed into 1690 qdo should be 1.690 ?

HereistheController(thereinjavascriptIdeletedsomefieldstogetcleanerandeasierunderstanding):

HTML

<inputtype="text" name="inss" id="inss" value="" class="form-control" />

Javascript

 $("#btnCadastrar").on("click", function () {
                 var _fornecedor = { 
                 "FornecedorID": $("#FornecedorID").val(),
                 "Imposto":[]
             };
             var _inss = parseFloat($("#inss").val().replace(",", ".")).toFixed(3);

             _fornecedor.Imposto.push({
                 "INSS": _inss
             });

             $.ajax({
                 url: "/Fornecedor/IncluirJSON",
                 type: "post",
                 dataType: "json",
                 contentType: "application/json; charset=utf-8",
                 processData: false,
                 data: JSON.stringify(_fornecedor),
                 success: function (data) {
                     window.location.href = "/Fornecedor/Index";
                 },
                 error: function (result) {
                     alert(result.responseText);
                 }
             });
         });

MODEL

public class Imposto
    {
        [HiddenInput(DisplayValue = false)]
        public int ImpostoID { get; set; }
        public int FornecedorID { get; set; }
        public decimal? INSS { get; set; }
        public virtual Fornecedor Fornecedor { get; set; }
    }
    
asked by anonymous 31.01.2016 / 20:58

1 answer

1

Solution:

var _inss = $("#inss").val().replace("%", "").replace(",", ".") == '' ? "0.00" : parseFloat($("#inss").val().replace("%", "").replace(",", ".")).toFixed(3);

and then:

_fornecedor.Imposto.push({
            "INSS": JSON.parse(_inss)
        });
    
01.02.2016 / 11:23