I have a couple of hidden inputs on an asp.net mvc view. Their values contain objects of type double
. I want them to be rendered with the InvariantCulture
as they are used to be fed to an api (google maps) on the client. As it is now, they get rendered with a comma (,) as decimal separator, while the api expects a point (.) as decimal separator.
The nicest solution would be if I could specify a culture in the DisplayFormat
data annotation attribute on the property on the model, but I don't think that is possible:
public class Position
{
[DisplayFormat(DataFormatString="{0:G}, CultureInfo.InvariantCulture")]
public double Latitude;
...
}
I can't also just set the CurrentCulture
to InvariantCulture
in my Application_Start
method, as there are other values on the screen which have to be in the proper user culture.
So, is there a way to just temporarily change the current culture, right before I do an Html.HiddenFor(Model => Model.Latitude)
for that specific property, and then reset it afterwards?
Or is there another better way of doing this? What is considered best practice concerning this?