MVC在ajax.begin外部提交表单

MVC在ajax.begin外部提交表单,ajax,asp.net-mvc-3,razor,Ajax,Asp.net Mvc 3,Razor,我有一个特定的ajax表单,当提交时,我希望在该ajax表单之外包含另一个表单。让我给你举个例子: @using (Ajax.BeginForm("PayWithBankTransfer", "Payment", new { salesLineId = salesLine.SalesLineID }, new AjaxOptions

我有一个特定的ajax表单,当提交时,我希望在该ajax表单之外包含另一个表单。让我给你举个例子:

    @using (Ajax.BeginForm("PayWithBankTransfer", "Payment", new { salesLineId = salesLine.SalesLineID }, new AjaxOptions
                                                                                                                    {
                                                                                                                        HttpMethod = "POST",
                                                                                                                        UpdateTargetId = "bankForm",
                                                                                                                        LoadingElementId = "spinnerBank"
                                                                                                                    }, new { id = "feedback-form" }))
{
    //some stuff
    <button type="submit">Reserve</button>
}
@使用(Ajax.BeginForm(“PayWithBankTransfer”,“Payment”,新的{salesLineId=salesLine.salesLineId},新的AjaxOptions
{
HttpMethod=“POST”,
UpdateTargetId=“银行表单”,
LoadingElementId=“喷丝板组”
},新的{id=“反馈表”})
{
//一些东西
储备
}
我想在ajax表单提交中包含表单之外的另一个标记

<div id="theOtherStuff">
    //otherStuff
</div>

//其他东西

我如何在提交ajax表单的同时提交其他内容?

我认为MS unobtrusive ajax不支持这一点。所以,让我们去掉它,使用普通jQuery。方法就是你要找的

因此,我们首先将
Ajax.BeginForm
表单替换为常规的
Html.BeginForm

@using (Html.BeginForm(
    "PayWithBankTransfer", 
    "Payment", 
    new { salesLineId = salesLine.SalesLineID }, 
    FormMethod.Post,
    new { id = "feedback-form" })
)
{
    //some stuff
    <button type="submit" class="t-button t-state-default" style="width: 100px; height: 50px;">Reserver</button>
}
应特别注意以下几行:

data: $(this).add('#theOtherStuffForm').serialize(),
如您所见,.serialize方法允许将多个表单转换为合适的序列化表单


更明显的是,您不应该与这两个表单的输入元素有冲突的名称(例如,有两个同名的元素),否则默认的模型绑定器可能会崩溃。如果有冲突,由您来解决。

我不认为MS unobtrusive AJAX支持这一点。所以,让我们去掉它,使用普通jQuery。方法就是你要找的

因此,我们首先将
Ajax.BeginForm
表单替换为常规的
Html.BeginForm

@using (Html.BeginForm(
    "PayWithBankTransfer", 
    "Payment", 
    new { salesLineId = salesLine.SalesLineID }, 
    FormMethod.Post,
    new { id = "feedback-form" })
)
{
    //some stuff
    <button type="submit" class="t-button t-state-default" style="width: 100px; height: 50px;">Reserver</button>
}
应特别注意以下几行:

data: $(this).add('#theOtherStuffForm').serialize(),
如您所见,.serialize方法允许将多个表单转换为合适的序列化表单

更明显的是,您不应该与这两个表单的输入元素有冲突的名称(例如,有两个同名的元素),否则默认的模型绑定器可能会崩溃。如果有冲突,由你来解决