string format in an input that receives value from ajax

0

I have a textbox, which receives a data by AJAX.

@Html.TextBox("CantidadPago", string.Format("{0:C}",0), new{@class = "form-control"})

AJAX

$.ajax({ 
       type: 'POST', 
       url: '@Url.Action("CalcularCantidadPago")', 
       datatype: 'json', 
       data: {totalC: $("#Total").val()},
       success: function (Precios) { 
       $("#CantidadPago").val(Precios[0]); },

});

And then I get it like that

and what I want is to format it. Something like this:

I tried with string.Format("{0:C}",0) , but when I assign the value brought to the textbox it deletes the format.

How can I make it so that when I receive the data I keep the format and sending it does not affect my operation?

    
asked by Xique 06.10.2016 в 23:18
source

1 answer

1

You could format it before setting the input value with jquery, it would be something like this:

$.ajax({ 
   type: 'POST', 
   url: '@Url.Action("CalcularCantidadPago")', 
   datatype: 'json', 
   data: {totalC: $("#Total").val()},
   success: function (Precios) { 
   $("#CantidadPago").val('$' + parseFloat(Precios[0]).toFixed(2)); },
});
    
answered by 06.10.2016 / 23:37
source