0

I am storing a currency with the decimal data type.

public decimal money { get; set; }

I want to display this with a "£" sign. so I am using

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")]

This works fine. The value is displayed in a table with is serialized using jQuery.

@Html.EditorFor(model => model.money, "Currency")

Once the information is serialized I then make an ajax post to get the information back to my ActionResult.

Data = $('#container :input').serialize();

public PartialViewResult EditedValue(MoneyModel viewModel)
{
        return PartialView("_MoneyView", viewModel);
}

This MoneyModel object contains the decimal money. THE PROBLEM, money is converted to a string in the view and when it is serialized it remains as a string. This can not be cast to a decimal in the MoneyModel.

How should I resolve this issue? I would like to keep the "£" and the "," for a formatted currency "£1,000" but I do not want to have conver decimal money -> string money in MoneyModel.

Sigex
  • 2,834
  • 2
  • 24
  • 25
  • Please check this link, It may helps you. https://stackoverflow.com/questions/2753701/convert-any-currency-string-to-double – Mobeen Ikhtiar Oct 15 '18 at 10:08

1 Answers1

0

Just send the input value like this :

$.ajax({
  type: 'POST',
  contentType: "application/json; charset=utf-8",
  url: 'yoururl',
  data: {val: $('#container :input').val()},
  success: function (data) {  
     // do stuff  
  },
});
WebAddict
  • 51
  • 5