public ActionResult Create([Bind(Include = "MarkID,Lat,Lng,Title")] Mark mark) { if (ModelState.IsValid) { db.Marks.Add(mark); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mark)); }
public JsonResult Create(Mark model) { MarkDbContext db = new MarkDbContext(); try { model.ID = Guid.NewGuid().ToString(); db.Marks.Add(model); db.SaveChanges(); return(Json(new{ Result = "OK", Records = model }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Edit(Mark model) { MarkDbContext db = new MarkDbContext(); try { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(Json(new { Result = "OK" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); //throw; } }
public JsonResult Delete(string ID) { MarkDbContext db = new MarkDbContext(); try { //删除,是先找到,在删除 Mark marks = db.Marks.Find(ID); db.Marks.Remove(marks); db.SaveChanges(); return(Json(new { Result = "OK" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); //throw; } }