I’m having this issue in which I have a log in screen and a register screen in different cshtml files, but the register view is called as a @Html.Partial. The code in the log in screen is as follows:
<div class="panelLogIn left @if (ViewBag.register) { Write("hidden"); }">
@using (Html.BeginForm()) {
<div>
<div class="validationMessage" style="padding-bottom:10px;">@Html.ValidationMessage("loginFailed")</div>
<div class="field">
<span class="textOverField absolute em1-2" style="top:6px;left:4px;">User</span>
@Html.TextBoxFor(a => a.UserName, new { @class = "textField" }) <div class="absolute validationMessage">@Html.ValidationMessageFor(u => u.UserName)</div>
</div>
<div class="field relative">
<span class="textOverField absolute em1-2" style="top:6px;left:4px;">Password</span>
@Html.PasswordFor(a => a.Password, new { @class = "textField" }) <div class="absolute validationMessage">@Html.ValidationMessageFor(u => u.Password)</div>
</div>
<div class="em0-9" style="margin-bottom: 20px;">
<input class="submitButton cursorHand" style="margin-top: 10px;" type="submit" value="Enter" />
</div>
<div class="em0-9">
<span class="guestLink bold linkBlue underline cursorHand">Register Free</span>
</div>
</div>
}
</div>
<div class="panelGuest left @if (!ViewBag.register) { Write("hidden"); }">
@Html.Partial("RegisterUser", Model.NewUser)
</div>
And the Register view is as follows:
@using (Html.BeginForm("Register", "Account"))
{
/* The text boxes and form elements */
<div class="em0-9" style="margin-bottom:20px;">
<input class="submitButton cursorHand" style="margin-top:10px;" type="submit" value="Register" />
</div>
}
Basically, the issue is that when I try to Register a new user, it redirects me to localhost/Account/Register and when I go back to the LogIn screen (which is in the same view) I can’t call any other action aside from the register one.
Any help with this will be greatly appreciated.
Try fully specifying the action of your first Html Form, as you have done in the Partial: