表单提交传值的两种方式:
1. JS中直接 post提交:
<form style="display:none" method="get"> <input name="addressId" type="hidden" value="111" /> <input name="cartIds" type="hidden" value="222" /> </form> <script> $('.paytbn').click(function () { var cartIds = $('form input[name=cartIds]').val(); var addressId = $('form input[name=addressId]').val(); var referNo = $('.order-referno').val(); var logistics = []; $.each($('select.logistics'), function () { var table = $(this).parents('.goods-table'); var map = table.attr('data-wareid') + '|' + $(this).val(); logistics.push(map); }); $.post('@Url.Action("SubmitOrder")', { cartIds: cartIds, addressId: addressId, logistics: logistics, referNo: referNo }, function (data) { if (data.flag) { location.href = '@Url.RouteUrl("PaymentOrder")' + "?orderNos=" + data.msg; }); }); </script>
2. JS中直接 模拟表单submit提交:
<form method="post" style="display:none"> <input name="QueryWay" type="hidden" /> <input name="OrderKwd" type="hidden" /> <input name="OrderStatus" type="hidden" /> </form> <script> $('#btnSubmit').click(function () { $('form input[name=QueryWay]').val(1); $('form input[name=ExportType]').val(2); $('form input[name=StartTime]').val(3); $('form').submit(); }); </script>
如果表单未指定提交地址,则直接提交当前页面。在该控制器下可以获取到表单传来的值