Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax.BeginForm内部Html.BeginForm多个提交按钮mvc_Ajax_Asp.net Mvc_Forms - Fatal编程技术网

Ajax.BeginForm内部Html.BeginForm多个提交按钮mvc

Ajax.BeginForm内部Html.BeginForm多个提交按钮mvc,ajax,asp.net-mvc,forms,Ajax,Asp.net Mvc,Forms,我的页面上有嵌套表单 @using (Html.BeginForm()) { @Html.TextBoxFor(model => model.ComapnyName, new { @class = "form-control", placeholder = @Resources.Customers.ComapnyName }) @Html.ValidationMessageFor(model => model.PhoneNuComapnyNamember, "", n

我的页面上有嵌套表单

@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" />   
}
@使用(Html.BeginForm())
{
@TextBoxFor(model=>model.ComapnyName,新的{@class=“form control”,占位符=@Resources.Customers.ComapnyName})
@Html.ValidationMessageFor(model=>model.phonenucomapynamber,“,new{@class=“text danger”})
//其他东西
添加
//引导模式
@使用(Ajax.BeginForm(“CreateCustomerDepartments”,“Customers”,null,新的AjaxOptions
{
HttpMethod=“Post”,
UpdateTargetId=“departmentsId”,
OnSuccess=“$('#部门模型”).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”})
//其他东西
//创建部门
}   
//创建公司
}
当我单击submit按钮(为主窗体创建)时,要求validator保留模态字段(Departments add)。我从添加部门开始,单击ModalPopp上的submit按钮,主窗体保留验证器

我试着

但页面无效,代码未到达控制器。
在我使用validationGroup的asp.net(web表单)上,如何获得与Ajax表单呈现为表单标记相同的效果,这意味着您将一个表单嵌套在另一个表单中,这是无法实现的

如果你想在一个视图上使用多个提交按钮,你可以这样做

  <button type="submit" name="button1" id="button1" class="btn btn-success" formaction = '@Url.Action("ActionMethod", "ConrollerName")'>View1</button> 
  <button type="submit" name="button2" id="button2" class="btn btn-success" formaction = '@Url.Action("ActionMethod", "ConrollerName")'>View2</button> 
View1
视图2
以上只是一个示例或周转方式,使用“formaction”属性在单个视图上使用不同的提交按钮来调用不同的控制器/操作方法

还可以将JSON请求与jQuery一起使用


希望这有帮助。

嵌套表单是无效的html,不受支持。在主窗体解决我的问题后,将内部模态窗体移动到!谁给它的链接是几个多提交按钮的正确方法?是否有更好的解决方案?@18666该链接显示了如何使用多个提交按钮而不是多个嵌套表单。正如@CodingYoshi所指出的,您误解了链接中的代码。它不使用嵌套表单-它使用按钮的
action
属性将一个表单提交给不同的方法。