I have a custom made class that use a long as ID. However, when I call my action using ajax, my ID is truncated and it loses the last 2 numbers because javascript loses precision when dealing with large numbers. My solution would be to give a string to my javascript, but the ID have to stay as a long on the server side.
Is there a way to serialize the property as a string? I'm looking for some kind of attribute.
Controller
public class CustomersController : ApiController
{
public IEnumerable<CustomerEntity> Get()
{
yield return new CustomerEntity() { ID = 1306270928525862486, Name = "Test" };
}
}
Model
public class CustomerEntity
{
public long ID { get; set; }
public string Name { get; set; }
}
JSON Result
[{"Name":"Test","ID":1306270928525862400}]