I am trying to persist geolocation data gotten by the google.maps.Geocoder().
From javascript I set the values into an (actually) hidden element in html (which is working fine):
document.getElementById("longitude").value = results[0].geometry.location.lng();
document.getElementById("latitude").value = results[0].geometry.location.lat();
From there I want to pass the values into the controller:
@Html.TextBoxFor(model => model.Longitude, new { id = "longitude", type = "number" })
@Html.TextBoxFor(model => model.Latitude, new { id = "latitude", type = "number"})
Depending on the decimal seperator I get either a validation error or the values for longitude and latitude are not set to the model. Both properties are type of long.
Why can’t Asp.Net parse the values automatically?
I am quite new to Asp.Net but I know I could else:
- write my own html-helper
- pass a view model into my controller or
- persisting the string values
Which way should I prefer?
Thanks, Rico
You’re getting errors because
longstores large 64-bit integer values (it’s actuallyInt64behind the scenes), not floating point values.If you want your code to work with floating point values, you’ll need to use something like
floatordouble.