I have created two razor forms in one view file in the view file i have created two Html.BeginForm()
and mentioned different controllers, but when i submit the form, form submits to same controller.
view file
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.TextBoxFor(m => m.email, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.email, "", new { @class = "text-danger" })
@Html.PasswordFor(m => m.password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.password, "", new { @class = "text-danger" })
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default" />
</div>
</div>
}
@using (Html.BeginForm(Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "login", id = "f1" })))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.ValidationSummary("", new { @class = "text-danger" })
<p class="form-row form-row-first input-required">
@Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "input-text" } })
@Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
@Html.PasswordFor(model => model.password, new { htmlAttributes = new { @class = "input-text" } })
@Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
@Html.PasswordFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "input-text" } })
@Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
@Html.EditorFor(model => model.first_name, new { htmlAttributes = new { @class = "input-text" } })
@Html.ValidationMessageFor(model => model.first_name, "", new { @class = "text-danger" })
@Html.EditorFor(model => model.last_name, new { htmlAttributes = new { @class = "input-text" } })
@Html.ValidationMessageFor(model => model.last_name, "", new { @class = "text-danger" })
@Html.EditorFor(model => model.address, new { htmlAttributes = new { @class = "input-text" } })
@Html.ValidationMessageFor(model => model.address, "", new { @class = "text-danger" })
<div class="clear"></div>
<input type="submit" value="Signup" name="signup" class="button btn btn-default" />
<div class="clear"></div>
}
Controller File
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login()
{
//Controller stuffs
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register()
{
//Controller stuffs
}
Each time when i submit the form it is going to register controller how to fix this?