我在視圖文件中的一個視圖文件中創建了兩個剃刀形式,我創建了兩個Html.BeginForm()
並提到了不同的控制器,但是當我提交表單時,表單提交給相同的控制器。ASP MVC多個剃鬚刀表單提交給相同的控制器?
視圖文件
@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
}
當我提交它要註冊控制器如何解決這個問題的形式每一次?
做它用@ Ajax.BeginForm()。檢查此[鏈接](http://www.c-sharpcorner.com/UploadFile/0c1bb2/ajax-beginform-in-Asp-Net-mvc-5/)如何使用Ajax.BeginForm –
你有錯字 - ' Html.BeginForm(Html.BeginForm' – Win
檢查標記並確保在客戶端呈現時,表單html標記的邊界安裝正確。 –