public void OnPost() { if (!ModelState.IsValid) { return; } if (_userService.HasExist(Register.Name)) { ModelState.AddModelError("Register.Name", "*用户名已经存在"); return; } _userService.Register(Register.Name, Register.PassWord); Response.Redirect("Index"); }
//[AutoValidationFilter] public ActionResult Home(UserModel user, UserModel model) { if (!ModelState.IsValid) { return(View()); } //if (model.Captcha != Session[CaptchaController.CAPTCHA].ToString()) //{ // ModelState.AddModelError("Captcha", "验证码输入错误"); // return View(model); //} if (_userRepository.HasExist(user.UserName)) { ModelState.AddModelError("user.UserName", "*用户名重复"); } _userRepository.Register(user.UserName, user.Password); //CurrentData.db.Users.Add(user); //CurrentData.db.SaveChanges(); return(Redirect("/Register/Login")); }