Reputation: 715
I'm loading different forms into the same div, based on a drop down... all the others seem to work when they're told to submit via JQuery except this one... anyone know why? Thanks....
@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" />
}
Here's a form that does work...
@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)
}
They both post back to the same place... but the first one won't. These forms are loaded into a div in a parent view that has a save button... that button opens a dialog, that has an OK button with this in its click: $('#paymentSection2').find('form').submit();
Upvotes: 2
Views: 1808
Reputation: 101614
Why aren't you using @Html.HiddenFor()
? Chances are it's a binding issue and MVC can't distinguish your input names and the input names its expecting. (e.g. It may be expecting MyModel.PaymentID
instead of just PaymentID
as an input name).
Try the following:
@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)
}
Upvotes: 3