1
Because when sending a request with a decimal type (3) the "Point" is deleted, see in the field INSS which is a decimal value, for example: I type 1,69
when making a bind in the template the stitch is deleted and transformed into 1690
what should be 1.690
?
Here is the Controller (there in javascript I eliminated some fields to be cleaner and easier to understand):
HTML
<input type="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; }
}
As far as I know the decimal is written with . (Point) in C#, ie you should pass 1.69 instead of 1.69.
– Marco Souza