I have an MVC model with a DBGeometry field
[Required(AllowEmptyStrings = false, ErrorMessage = "Location is required")]
public System.Data.Entity.Spatial.DbGeography LocationGps { get; set; } // LocationGPS
Inside my View i have this hidden values.
@Html.HiddenFor(model => model.LocationGps)
@Html.HiddenFor(model => model.Lat)
@Html.HiddenFor(model => model.Lng)
When I edit the model I write the following to my Controller
model.LocationGps = Utils.Geography.ConvertLatLonToDbGeography(model.Lng, model.Lat);
if (ModelState.IsValid)
{}
ConvertLatLonToDbGeography code:
public static DbGeography ConvertLatLonToDbGeography(double longitude, double latitude)
{
var point = string.Format("POINT({1} {0})", latitude, longitude);
return DbGeography.FromText(point);
}
But ModelState is always Invalid because LocationGps is null. how can I set properly values to my LocationGps parameter through my View? The consept is to have a google map, get the coords from javascript (stored in Lat & Lng fields) and then set my LocationGps properly. How can I do that?