I'm working with ASP MVC 5 and DataTables plugin and I'm having some problems formating my decimals.
I need to format numbers with dot as thousand separator and comma as decimal separator.
I'm trying to do it with DisplayFormat, but since i'm returning the data as Json, it just not applying
This is a little example of my problem
public class MyClass
{
[DisplayFormat(DataFormatString = "{0:0.##}")]
decimal MyDecimal {get;set;}
}
In the controller
public JsonResult LoadDataTables()
{
using(var db = new ExampleContext())
{
var data = db.MyRepository.Select(x => new MyClass
{
MyDecimal = x.mydecimal
}).ToList();
//i'm ignoring a lot of processing to create a short snippet
return Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data });
}
}
Then, in the front end, the json arrives with comma for thousands and dot for decimal separation
How can i deal with it? Some way to apply CultureInfo or manually set the conversion?
Edit: In my view, this is how i'm loading the data
var table = $('#myTabla').DataTable({
processing: true,
serverSide: true,
filter: true,
orderMulti: false,
paging: true,
pageLength: 10,
ajax: {
"url": '@Url.Action("LoadDataTables")',
"type": "POST",
"datatype": "json",
});
Thanks!