1

私は次のウェブページを持っています:

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()->ForgotPasswordビュー->[HttpPost] ActionResult ForgotPassword(ForgotAccountInfoModelモデル)-> ActionResult SecurityQuestion()->SecurityQuestionビュー-> [HttpPost] ActionResult SecurityQuestion(SecurityQuestionModelモデル)

代わりにこれを行っています:

ActionResult ForgotPassword()->ForgotPasswordビュー->[HttpPost] ActionResult ForgotPassword(ForgotAccountInfoModelモデル)-> ActionResult SecurityQuestion()->SecurityQuestionビュー-> [HttpPost] ActionResult ForgotPassword(ForgotAccountInfoModelモデル)

そして、私の人生の間、なぜそれがForgotPasswordPOSTをリロードしているのか理解できません!!!!

誰かが私が欠けているものを見ますか?

4

1 に答える 1

1

まあ、なぜそれがそれをしているのか分かりませんが、私は回避策を実行しました:

CREATEビューはコントローラーからのcreateメソッドをポストしません

これを行うことにより、適切なメソッドを呼び出すように強制しました。

@using (Html.BeginForm("SecurityQuestion", "Account", FormMethod.Post))

多分これは他の誰かを助けるでしょう

于 2012-11-15T17:05:24.070 に答える