【发布时间】:2017-07-21 12:09:46
【问题描述】:
我正在尝试将值传递到操作链接中以调用 Iframe 中的控制器方法,这是我的代码:
控制器:
public ActionResult CallFastPay(string monateryAmount)
{
//some code logic here
}
查看:
@{
ViewBag.Title = "FastPay";
var url = ViewBag.url;
}
<h2>FastPay</h2>
<script src="~/Scripts/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(function() {
$('#myButton').click(function () {
var url = '@Url.Action("CallFastPay")'
var amount = document.getElementById("monateryAmount").value
$('#myFrame').attr(@Url.Action("CallFastPay", amount));
});
});
</script>
<br />
<iframe id="myFrame" width="600" height="500"></iframe>
<br />
<span>Amount</span>
<input type="text" class="form-control" id="monateryAmount" name="monateryAmount" />
<br />
<button id="myButton" onclick="">Submit</button>
我收到当前上下文中不存在数量的错误。任何帮助将不胜感激。
【问题讨论】:
-
如果你 console.log 的数量,你会得到什么?它是未定义的还是有值的?
-
是的,它在文本框中插入了值
-
你不能像这样混合剃须刀代码(你的
@Url.Action())和javascript变量(amount)。一个在服务器上执行,另一个在浏览器上执行 -
有什么解决办法吗?我做了很多研究,但真的一无所获
-
你可以使用ajax调用来调用方法和传递参数
标签: javascript c# asp.net-mvc asp.net-mvc-4 razor