Mr A
Mr A

Reputation: 6768

Can one handle Multiple Post Form Actions on One View in MVC

Just need to if i can use to form=post in the mvc view , below is the example which uses to form post , which currently doesnt works: Edited: the jquery is submiting the form with id frmWorldPay when the image is clicked

        $("#pay").click(function () {
       // $("#frmWorldPay").(function () {
       if ($("#terms").attr("checked")) {
        $("#frmWorldPay").submit();
        alert("sss");
         // return true;
        } else {
            alert("Please agree to the terms and conditions.");
            return false;
        }
    });

                 <% using (Html.BeginForm()) {%>

                    <table id="cart" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <th>
                                Event
                            </th>
                            <th>
                                Item
                            </th>
                            <th>
                                Quantity
                            </th>

                        </tr>
                        <% 
                            foreach (var bookingItem in Model.BookingItems)
                            {%>
                        <tr>
                            <td>
                                <%: ViewBag.Name %>
                            </td>
                            <td>
                                <%: Product.Description %>
                            </td>
                            <td>
                                <%: bookingItem.Quantity%>
                            </td>

                        </tr></table>
                        <%  } %>
                     <% { %>  if (ViewBag.mode == "confirm")
                       { %>
                            <input type="submit" value="Confirm" />
                    <% } %>


                    <form method="post" action="https://secure.wp3.rbsworldpay.com/wcc/purchase" id="frmWorldPay">

                    <input type="hidden" name="instId" value="01" />
                    <input type="hidden" name="cartId" value="<%: Model.GUID %>" />
                    <input type="hidden" name="currency" value="GBP" />

                    <input type="hidden" name="testMode" value="100" />
                     </form> if (ViewBag.mode == "Checkout")
                       { %>

                            <div id="worldPayBtnWrap">

                   <p> <%: Html.CheckBox("terms") %> by ticking this box you are agreeing to our <%: Html.ActionLink("terms & conditions", "Terms", "About")%></p>
                        <input type="image" src="/content/images/btnWorldPay.png" alt="Pay via World Pay" id="pay" />
                    </div>
                    <% } %>

Upvotes: 0

Views: 659

Answers (2)

Mr A
Mr A

Reputation: 6768

I have sorted out the issue , actually my input was in same post method , therfore only one form was posting while the other input was not posting , the above is modified which works fine , although it is not a clean solution , for the time being i will be happy to use , will clean it later on .:)

Upvotes: 1

SLaks
SLaks

Reputation: 887385

You can have multiple forms in one web page, but you can't nest them.

Your external form is nested inside the MVC form (the using (Html.BeginForm()) { }), so it won't work.

Upvotes: 2

Related Questions