我正在根据下拉列表将不同的表单加载到同一个div中......所有其他表单在被告知通过JQuery提交时似乎工作除了这个...有人知道为什么吗?感谢....
@using (Html.BeginForm("SaveInMemoryPayment", "Payment", FormMethod.Post))
{
@Html.ValidationSummary(true)
<p> Payment type: Cash. No further action needed. Plase click Save to finish. </p>
<input type="hidden" name="PaymentTypeID" id="paymentTypeIDHidden" value="@Model.PaymentTypeID" />
<input type="hidden" name="DonationID" id="donationIDHidden" value="@Model.DonationID" />
<input type="hidden" name="PaymentDate" id="paymentDateHidden" value="@Model.PaymentDate" />
<input type="hidden" name="PaymentAmount" id="paymentAmountHidden" value="@Model.PaymentAmount" />
}
这是一个有效的表格......
@using (Html.BeginForm("SaveInMemoryPayment", "Payment", FormMethod.Post))
{
@Html.ValidationSummary(true)
<p>Check information:</p>
<div class="editor-label" id="check1">
@Html.LabelFor(model => model.CheckNumber)
</div>
<div class="editor-field" id="check1.2">
@Html.EditorFor(model => model.CheckNumber)
@Html.ValidationMessageFor(model => model.CheckNumber)
</div>
@Html.HiddenFor(x => x.PaymentTypeID)
@Html.HiddenFor(x => x.DonationID)
@Html.HiddenFor(x => x.PaymentDate)
@Html.HiddenFor(x => x.PaymentAmount)
}
他们都回到同一个地方......但第一个不会。这些表单被加载到父视图中的div中,该视图具有一个保存按钮...该按钮打开一个对话框,在其单击中有一个OK按钮:$('#paymentSection2')。find('form') .submit();
答案 0 :(得分:3)
为什么不使用@Html.HiddenFor()
?有可能是一个绑定问题,MVC无法区分您的输入名称和它期望的输入名称。 (例如,可能需要MyModel.PaymentID
而不只是PaymentID
作为输入名称。)
尝试以下方法:
@using (Html.BeginForm("SaveInMemoryPayment", "Payment", FormMethod.Post))
{
@Html.ValidationSummary(true)
<p> Payment type: Cash. No further action needed. Plase click Save to finish. </p>
@Html.HiddenFor(x => x.PaymentTypeID)
@Html.HiddenFor(x => x.DonationID)
@Html.HiddenFor(x => x.PaymentDate)
@Html.HiddenFor(x => x.PaymentAmount)
}
答案 1 :(得分:2)
是的,您可以提交仅包含隐藏字段的表单。