我在视图文件的一个视图文件中创建了两个剃刀形式,我创建了两个Html.BeginForm()
并提到了不同的控制器,但是当我提交表单时,表单提交给同一个控制器。
查看文件
@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>
}
控制器文件
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login()
{
//Controller stuffs
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register()
{
//Controller stuffs
}
每当我提交表格时,它都会注册控制器如何解决这个问题?
答案 0 :(得分:0)
尝试在Html.BeginForm
@using (Html.BeginForm(actionName: "Register", controllerName: "Account", method: FormMethod.Post, htmlAttributes: new { @class = "login", id = "f1" }))
另外我相信你有一个错字Html.BeginForm(Html.BeginForm