[英]Send input value to Url.Action
我有以下内容:
<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
操作方法是类型的HttpGet
。 我该怎么做这样的new {price = toPay.Value}
<form method="get" action="@Url.Action("MyAction", "MyController")" >
@Html.Textbox("toPay")
<input type="submit" value="Pay"/>
</form>
输入元素必须在同一表格内
<form action="@Url.Action("Create", "Home")">
<div>
<input id="toPay" type="text" readonly>
</div>
<div>
<input type="submit" value="Pay"/>
</div>
</form>
然后,数据将作为POST消息在http正文中传递。
尝试这个 :
<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>
有了帮助者,它会变得更加容易:
@using (Html.BeginForm("Create", "Home", FormMethod.Get))
{
@Html.Textbox("toPay")
<input type="submit" value="Pay" />
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.