我有以下网页:
SecurityQuestion.cshtml
@model SuburbanCustPortal.Models.SecurityQuestionModel
@{
ViewBag.Title = "Forgot Password Step 2";
}
<h2>Forgot Password Step 2</h2>
<p>
Please provide the answer to your security question that you gave when you created your web account.
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
<div>
<fieldset>
<legend>Security Question and Answer</legend>
<!-- this is the question -->
<div class="editor-label">
@Html.LabelFor(m => m.SecurityQuestion)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.SecurityQuestion, new { @class = "GenericTextBox", @readonly = "readonly" })
</div>
<!-- this is the answer -->
<div class="editor-label">
@Html.LabelFor(m => m.SecurityAnswer)
</div>
<div class="editor-field focus" >
@Html.TextBoxFor(m => m.SecurityAnswer, new { @class = "GenericTextBox" })
@Html.ValidationMessageFor(m => m.SecurityAnswer)
</div>
@Html.ValidationSummary(true, "The supplied answer did not match the answer on the account.")
<p>
<input type="submit" value="Complete Step 2" />
</p>
</fieldset>
</div>
}
ForgotPassword.cshtml
@model SuburbanCustPortal.Models.ForgotAccountInfoModel
@{
ViewBag.Title = "Forgot Password Step 1";
}
<h2>Forgot Password Step 1</h2>
<p>
Please provide the username or email address on your web account.
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
<div>
<fieldset>
<legend>Email address</legend>
<div class="editor-label">
@Html.LabelFor(m => m.UsernameOrEmail)
</div>
<div class="editor-field focus">
@Html.TextBoxFor(m => m.UsernameOrEmail, new { @class = "GenericTextBox" })
@Html.ValidationMessageFor(m => m.UsernameOrEmail)
</div>
@Html.ValidationSummary(true, "Username or Email address was not found.")
<p>
<input type="submit" value="Complete Step 1" />
</p>
<br/>
<p align="right">
Step 1 of 3
</p>
</fieldset>
</div>
}
这是在我的控制器中:
public ActionResult SecurityQuestion()
{
return View();
}
[HttpPost]
public ActionResult SecurityQuestion(SecurityQuestionModel model)
{
const int maxnumberofattemptsallowed = 3;
if (model.SecurityAnswerAttempts > (maxnumberofattemptsallowed -1))
{
var msg =
string.Format(
"Max number of attempts allowed. Your account has been locked.{0}Please contact us for assistance in unlocking your account.",
"<br>");
ModelState.AddModelError("SecurityAnswer", msg);
return View("LogOn");
}
if (_client.ValidateSecurityAnswer(model.AccountId, model.SecurityAnswer))
{
var msg =
string.Format(
"The supplied answer did not match the answer on the account.{0}You have {1} more attempt(s) before your account is locked.",
"<br>", maxnumberofattemptsallowed - model.SecurityAnswerAttempts);
model.SecurityAnswerAttempts++;
ModelState.AddModelError("SecurityAnswer", msg);
return View(model);
}
// send email here
return View(model);
}
public ActionResult ForgotPassword()
{
return View();
}
[HttpPost]
public ActionResult ForgotPassword(ForgotAccountInfoModel model)
{
var tokenid = MiscClasses.TokenIdCookie.GetTokenIdCookie();
var secdata = new SecurityData();
secdata.EmailOrUsername = model.UsernameOrEmail;
secdata.TokenId = tokenid;
secdata = _client.ForgotPasswordGetSecurityQuestion(secdata);
if (!string.IsNullOrEmpty(secdata.SecurityQuestion))
{
var newmodel = new SecurityQuestionModel();
newmodel.SecurityQuestion = secdata.SecurityQuestion;
newmodel.SecurityAnswer = string.Empty;
newmodel.SecurityAnswerAttempts = 0;
newmodel.AccountId = secdata.AccountId;
return View("SecurityQuestion", newmodel);
}
{
ModelState.AddModelError("EmailAddressNotFound", "Email address not found.");
return View(model);
}
}
它应按以下方式行事:
ActionResult ForgotPassword() - &gt; ForgotPassword View - &gt; [HttpPost] ActionResult ForgotPassword(ForgotAccountInfoModel model) - &gt; ActionResult SecurityQuestion() - &gt; SecurityQuestion视图 - &gt; [HttpPost] ActionResult SecurityQuestion(SecurityQuestionModel模型)
相反,它正在执行此操作:
ActionResult ForgotPassword() - &gt; ForgotPassword View - &gt; [HttpPost] ActionResult ForgotPassword(ForgotAccountInfoModel model) - &gt; ActionResult SecurityQuestion() - &gt; SecurityQuestion视图 - &gt; [HttpPost] ActionResult ForgotPassword(ForgotAccountInfoModel模型)
对于我的生活,我无法弄清楚为什么它正在重新加载ForgotPassword POST !!!!
任何人都能看到我错过的东西吗?
答案 0 :(得分:1)
好吧,我不知道它为什么这样做,但我做了一个解决方法:
CREATE view does not Post the create method from the controller
我强迫它通过这样做来调用正确的方法:
@using (Html.BeginForm("SecurityQuestion", "Account", FormMethod.Post))
也许这会帮助其他人