I have a problem when submitting the form for a new creation, the problem that I can not validate the data of variable dbgeometry .. the error message is "No constructor without parameter defined for this object." this is my code controller :
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id,name,Location")] schoolinfo schoolinfo)
{
if (ModelState.IsValid)
{
db.schoolinfo.Add(schoolinfo);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(schoolinfo);
}
my model from EF :
public partial class schoolinfo
{
public string id { get; set; }
public string name { get; set; }
public System.Data.Entity.Spatial.DbGeography Location { get; set; }
}
the best way it's to use a sqlQuery command
var id = form["id"];
var name = form["name"];
var lat = form["Location.Latitude"];
var lng = form["Location.Longitude"];
db.Database.ExecuteSqlCommand("insert into [dbo].[schoolinfo] values ('" + id + "','" + name + "',geography::Point(" + lat + ", " + lng + ", 4326))");
it's 100% worked
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.