MVC中如何跳过对模型中某个属性的验证
[HttpPost] public ActionResult Create(Users user) { ModelState.Remove(“Password”); //加上这句就行了 if (ModelState.IsValid) { user.Password="admin"; db.Users.Add(user); db.SaveChanges(); return View("Index"); } return View(); }
[HttpPost] public ActionResult Create(Users user) { ModelState.Remove(“Password”); //加上这句就行了 if (ModelState.IsValid) { user.Password="admin"; db.Users.Add(user); db.SaveChanges(); return View("Index"); } return View(); }