2

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();

4
  • 1
    Why aren't you using @Html.HiddenFor()? Commented May 15, 2012 at 19:15
  • @Brad: Why would that matter? Commented May 15, 2012 at 19:16
  • Can you define "doesn't work"? To answer your question, Yes, you can have a form containing only hidden fields. Commented May 15, 2012 at 19:17
  • @scottm I added a little more detail to my question Commented May 16, 2012 at 4:50

2 Answers 2

3

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)
}
Sign up to request clarification or add additional context in comments.

Comments

2

Yes you can submit a form with only hidden fields.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.