【问题标题】:Can one handle Multiple Post Form Actions on One View in MVC一个人可以在 MVC 中的一个视图上处理多个表单操作吗
【发布时间】:2011-06-30 12:37:46
【问题描述】:

如果我可以在 mvc 视图中使用 to form=post 只需要,下面是用于形成 post 的示例,目前不工作: 已编辑:单击图像时,jquery 正在提交 id 为 frmWorldPay 的表单

        $("#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>
                    <% } %>

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-2 forms http-post


    【解决方案1】:

    一个网页中可以有多个表单,但不能嵌套。

    您的外部表单嵌套在 MVC 表单(using (Html.BeginForm()) { })内,因此无法正常工作。

    【讨论】:

    • 但是上面的例子不起作用..你的意思是我关闭html开始表单然后启动另一个表单,
    • 我尝试将两个表单分开,但仍然没有将操作发布到 https 网站
    • 试试$("#frmWorldPay")[0].submit()
    • 它仍然重新加载页面而不是重定向到 worlpay 页面
    • 获取底层DOM元素。
    【解决方案2】:

    我已经解决了这个问题,实际上我的输入是在相同的发布方法中,因此只有一个表单在发布而另一个输入没有发布,上面的修改效果很好,虽然它不是一个干净的解决方案,因为目前我会很乐意使用,以后会清理它。:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2013-10-15
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      相关资源
      最近更新 更多