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 prec
I would probably just create an anonymous type when I call the json serializer like;
JsonConvert.SerializeObject(new { instance.Name, instance.ID.ToString() } );
In the case where your class has 20 or something fields and this becomes a very ugly solution I would add a string to the class called ID, change the long to lID or something and use the serializer settings to ignore the long when serializing so the resulting json will only have the string version.
There are several different attributes that will accomplish this for example;
public class CustomerEntity
{
[ScriptIgnore]
public long _ID { get; set; }
public string ID { get; set; }
public string Name { get; set; }
}
Will not serialize _ID