public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var model = new LoginForm(); try { // do the bind model.EmailAddress = bindingContext.ValueProvider.GetValue("Email").AttemptedValue; model.Password = bindingContext.ValueProvider.GetValue("Password").AttemptedValue; // validate if (!_authService.IsValid(model.EmailAddress,model.Password )) { bindingContext.ModelState.AddModelError("", "Invalid credentials (so says the injected LoginFormBinder)"); } } catch (Exception ex) { bindingContext.ModelState.AddModelError("", ex); } return model; }
public ActionResult Login(LoginForm model) { if (ModelState.IsValid) { return RedirectToAction("LoginSuccess"); } return View(model); }