我有以下内容:
<div>
<form>
<input id="toPay" type="text" readonly>
</form>
</div>
<div>
<form action="@Url.Action("Create", "Home", new {price = toPay.Value})">
<input type="submit" value="Pay"/>
</form>
</div>
我想将toPay
值作为参数发送到类型为Create
的{{1}}操作方法。我该怎么做HttpGet
答案 0 :(得分:2)
<form method="get" action="@Url.Action("MyAction", "MyController")" >
@Html.Textbox("toPay")
<input type="submit" value="Pay"/>
</form>
答案 1 :(得分:1)
输入元素需要在同一个表单中
<form action="@Url.Action("Create", "Home")">
<div>
<input id="toPay" type="text" readonly>
</div>
<div>
<input type="submit" value="Pay"/>
</div>
</form>
然后,数据将作为POST消息在http正文中传递。
答案 2 :(得分:0)
试试这个:
<div>
<form>
<input id="toPay" type="text" readonly/> //close input tag
</form>
</div>
<div>
<form>
<input type="button" value="Pay" id = "pay"/> // make this change
</form>
</div>
<script>
$('#pay').click(function() {
$.ajax({
url: @Url.Action("Create", "Home") + '?price =' + $('#toPay').val()
type: 'POST',
// ... other ajax options ...
});
});
</script>
答案 3 :(得分:0)
并且帮助者更容易:
@using (Html.BeginForm("Create", "Home", FormMethod.Get))
{
@Html.Textbox("toPay")
<input type="submit" value="Pay" />
}