public ActionResult Create([Bind(Include = "UserId,UserName,UserPwd,RegDate")] UserInfo userInfo) { //if (ModelState.IsValid) //{ // db.UserInfo.Add(userInfo); // db.SaveChanges(); // return RedirectToAction("Index"); //} //return View(userInfo); try { // TODO: Add insert logic here db.UserInfo.Add(userInfo); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// 删除 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult DeleteUser(int id) { UserInfo userInfo = db.UserInfo.Where(u => u.UserId == id).FirstOrDefault(); if (userInfo != null) { db.Entry <UserInfo>(userInfo).State = System.Data.Entity.EntityState.Deleted; if (db.SaveChanges() > 0) { return(RedirectToAction("Index")); } else { return(Content("删除失败")); } } else { return(Content("要删除的数据不存在")); } }