When casting from a number the value must be a number less than infinity
In my controller below I'm receiving the following error "when casting from a number the value must be a number less than infinity". This occurs on the line that begins "var zones..."
This is my controller
public JsonResult LatLng()
{
var zones = zoneRepository.GetCoordinates().ToList();
//return Json(zones, JsonRequestBehavior.AllowGet);.
return Json(new { zones = zones }, JsonRequestBehavior.AllowGet);
}
This is my model
public IQueryable<Zone> GetCoordinates()
{
return db.Zones;
}
In my database table I have one column that is of type numeric and three columns that are of type float. Is there a way I can find out what value(s) my code is objecting to? My best guess is that this has something to do with my use of floats. However I'm not sure how to go about debugging this. Any guidance that points me in the direction of fixing this error would be great开发者_开发百科ly appreciated.
Note - there error only occurs at runtime
I converted my latitude and longitude columns in the database from float to decimal. This solved my problem. If someone would like to take the time to explain why this worked I will gladly mark that as the answer. For example, how is it that my coordinates are greater than infinity when a visual inspection of the data reveals that none are more than a few digits to the right and left of the decimal point?
精彩评论