【发布时间】:2017-01-22 11:07:10
【问题描述】:
我的页面上有嵌套表单。
@using (Html.BeginForm())
{
@Html.TextBoxFor(model => model.ComapnyName, new { @class = "form-control", placeholder = @Resources.Customers.ComapnyName })
@Html.ValidationMessageFor(model => model.PhoneNuComapnyNamember, "", new { @class = "text-danger" })
// other stuff
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target=".modal-lg-customer-departments">
<i class="fa fa-plus"></i> Add
</button>
//bootstrap modal
@using (Ajax.BeginForm("CreateCustomersDepartments", "Customers", null, new AjaxOptions
{
HttpMethod = "Post",
UpdateTargetId = "departmentsId",
OnSuccess = "$('#departmentsModal').modal('hide')"
}))
{
@Html.TextBoxFor(model => model.Name, new { @required = "require", @class = "form-control", placeholder = Resources.Common.Name })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
// other stuff
//Create departments
<input type="submit" value="@Resources.Common.Save" class="btn btn-success" name="CreateDepartments" />
}
//Create company
<input type="submit" value="@Resources.Common.Save" class="btn btn-success" name="Create" />
}
当我单击提交按钮(为主表单创建)时,需要验证器保留模态字段(depoartments 添加)。我从添加部门开始,然后单击 modalpopup 主窗体上的提交按钮,保留验证器。
我试过了
How to have multiple submit buttons in your MVC forms
但页面无效,代码未到达控制器。 在asp.net(web forms)上我使用validationGroup,如何得到同样的效果
【问题讨论】:
-
嵌套表单是无效的 html,不受支持。将内部模态窗体移动到主窗体之后
-
它解决了我的问题!谁给的链接 这是少数多重提交按钮的正确方法?如果有更好的解决方案?
-
@18666 该链接显示了如何使用多个提交按钮而不是多个嵌套表单。
-
正如@CodingYoshi 所指出的,您误解了链接中的代码。它不使用嵌套表单 - 它使用按钮的
action属性将一个表单提交给不同的方法。
标签: ajax asp.net-mvc forms