【发布时间】:2013-10-22 22:11:57
【问题描述】:
抱歉标题不好。
我正在尝试创建一个恢复密码页面。我打算将这一切作为具有多个状态的单个页面来完成,具体取决于模型信息(也许这不是一个好方法)。
恢复有 4 个步骤
- 验证用户输入的电子邮件
- 验证用户输入的第一个答案 安全问题
- 验证用户输入的第二个安全答案 问题
-
显示消息,说明已发送带有链接的电子邮件 重置密码。
[AllowAnonymous] public ActionResult RecoverPassword() { return View(new RecoverPassword()); } [AllowAnonymous] [HttpPost] public ActionResult RecoverPassword(RecoverPassword model) { var user = new Identity("", ""); ASResponse<string> asr; switch (model.View) { case "One": try { asr = Services.ValidateSecurityQuestionOne(user.Token, model.Email, model.Answer); model.View = "Two"; model.Question = "Your Other Favorite Color"; //asr.Payload; model.Answer = string.Empty; } catch (Exception) { ModelState.AddModelError("Question", "Incorrect Answer"); } break; case "Two": try { asr = Services.ValidateSecurityQuestionTwo(user.Token, model.Email, model.Answer); model.View = "Email"; model.Question = string.Empty; } catch (Exception) { ModelState.AddModelError("Question", "Incorrect Answer"); } break; case "Email": break; default: if (!string.IsNullOrEmpty(model.Email)) { try { asr = Services.ValidateEmail(user.Token, model.Email); model.View = "One"; model.Question = asr.Payload; } catch (Exception) { ModelState.AddModelError("Email", "Invalid Email"); } } break; } return View(model); } <div> <div>Retrieve your password</div> @{ using (@Html.BeginForm()) { @Html.HiddenFor(m => m.View) switch (Model.View) { case "One": case "Two": @Html.HiddenFor(m => m.Email) <h3>@Model.Question</h3> @Html.TextBoxFor(m => m.Answer) <br/> <input type="submit" value="Next" /> break; case "Email": <h3>Your email is on its way!</h3> break; default: <h3>Please enter your Account Email Address</h3> @Html.TextBoxFor(m => m.Email) <br/> <input type="submit" value="Next" /> break; } } } </div>
通过上述方法,我输入电子邮件,我得到了第一个问题,但是当我提交该答案时,model.View 为空,因此它返回到电子邮件问题。
创建这样的设置的适当方法是什么?或者我怎样才能让我的模型始终拥有视图和电子邮件?
【问题讨论】:
-
我不知道 ajax 回发是否是一种选择,但我认为这对你来说会更好。
标签: c# asp.net-mvc-4 postback