Setup:
I am working on reset password
page and planning to have a single view to display three forms one after another.
Initially user will be asked to enter username, then the form gets submitted.
I am able to capture it is HttpPost
action method.
I am returning the same view but this time I am rendering a different form, I am doing this using Razor
When I try to submit (calling a different action method) from the second form that I am displaying now I am getting and error saying that Resource cannot be found
Question: Is it not possible to post back twice from the sample page/view? If possible how can I achieve it?
CSHTML:
@if (ViewBag.step == 1) {
<form id="frmUsername" action="@Url.Content("~/Account/ValidateAnswers")" method="post" novalidate="novalidate" ng-init="initStep1()">
...
</form>
}
@if (ViewBag.step == 2) {
<form action="@Url.Content("~/Account/ValidateUsername")" id="frmQuestions" ng-init="initStep2()" novalidate="novalidate">
...
</form>
}
Controller methods:
public ActionResult RecoverPassword(string userType)
{
ViewBag.step = 1;
ViewBag.userType = userType;
ViewBag.showUsernameErrorMessage = "false";
return View();
}
[AllowAnonymous]
[HttpPost]
public ActionResult ValidateUsername(string userName, string selectedUserType)
{
...
ViewBag.step = responseStep;
ViewBag.showUsernameErrorMessage = responseShowUsernameErrorMessage;
ViewBag.userName = userName;
ViewBag.userType = selectedUserType;
return View("~/Views/Account/RecoverPassword.cshtml");
}
[HttpPost]
public ActionResult ValidateAnswers(string answer1, string answer2, string answer3, string questionId1, string questionId2, string questionId3, string step, string userName, string selectedUserType)
{
...
ViewBag.step = responseStep;
ViewBag.showUsernameErrorMessage = responseShowUsernameErrorMessage;
ViewBag.userName = userName;
ViewBag.userType = selectedUserType;
return View("~/Views/Account/RecoverPassword.cshtml");
}