Looks like that JsonValueProviderFactory (from Microsoft.Web.Mvc) that I’m using in my ASP.NET MVC2 project is culture specific.
I send this JSON from client:
{
"name": "Max",
"weight": "60.21"
}
JsonValueProviderFactory converts JSON to this class:
public class User
{
public string Name { get; set; }
public double Weight { get; set; }
}
Everything works correctly if my current culture is CultureInfo.InvariantCulture. But if I explicitly set my culture to “ru-RU” User’s Weight value will be 0.0
Ok, I can send formatted value based on culture for weight from client, for example:
{
"name": "Max",
"weight": "1,100.21" // it's just example, not my real weight :)
}
But in this case JsonValueProviderFactory can’t parse weight and it will be zero, although double.Parse(“1,100.21”, CultureInfo.CurrentCulture) works correctly.
How I can resolve this problem?
If the
weightproperty is supposed to be double, send it as such, not as string: