加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 添加附加参数以表单提交

发布时间:2020-12-16 00:21:39 所属栏目:asp.Net 来源:网络整理
导读:我的剃须刀视图中有一个表单声明 form method="post" action="/Lot/LotList?auctionEventId=@auctionEventId" id="filterForm" (顺便提一下,我选择这样写出来,而不是使用Html.BeginFrom,因为我需要给它一个id,不知道如何使用Html.BeginFrom – 但这不是
我的剃须刀视图中有一个表单声明
<form method="post" action="/Lot/LotList?auctionEventId=@auctionEventId" id="filterForm">

(顺便提一下,我选择这样写出来,而不是使用Html.BeginFrom,因为我需要给它一个id,不知道如何使用Html.BeginFrom – 但这不是这里的问题)

在此表格之外,我有一个提交此表单的按钮(表单中还有一个提交按钮)

<input type="button" onclick="$('#filterForm').submit();" value="Show all" />

现在的问题是,如果这个按钮用于提交表单,我想要的形式的动作改为

action="/Lot/LotList?auctionEventId=@auctionEventId&showAll=true"

如何更改操作并传递此附加参数?有没有一个更好的方式做这一切?

解决方法

将查询字符串参数附加到表单操作上,并尝试在运行时更改它是棘手的(但不是不可能)。更容易使用隐藏的字段:
<form method="post" action="/Lot/LotList" id="filterForm">
  <input type="hidden" name="auctionEventId" value="@auctionEventId" />
  ...

所以现在所有你需要做的是为“showAll”添加另一个隐藏的字段

<form method="post" action="/Lot/LotList" id="filterForm">
  <input type="hidden" name="auctionEventId" value="@auctionEventId" />
  <input type="hidden" name="showAll" value="false" id="showAllField" />
  ...

并且只需在您的showAll按钮上连接一个jquery事件:

<input id="showAllButton" type="button"/>

jQuery的:

$('#showAllButton').click(function(){
     $('#showAllField').val("true");
     $('#filterForm').submit();
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读