我正在尝试将值传递到动作链接以调用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>
我收到的错误是当前上下文中不存在金额。任何帮助将不胜感激。
答案 0 :(得分:0)
像这样更改你的剧本,
$('#myButton').click(function () {
//var url = '@Url.Action("CallFastPay")'
var amount = $("#monateryAmount").val();
$.ajax({
url:"YourControllerName/CallFastPay/"+amount,
//Or you can write like this, url: url + '/' + amount,
type:"Get",
success:function(data)
{
//Your success message here, for example
alert("Amount submitted successfully!");
}
error:function(data)
{
//Your error message here
}
})
});
希望它有所帮助!
答案 1 :(得分:0)
使用方法如下:由于您的syntex错误。
$('#myButton').click(function () {
var amount = $("#monateryAmount").val();
$.ajax({
url:'@Url.Action("CallFastPay","ControllerName")',
data:{'monateryAmount':amount},
type:Get,
success:function()
{
//Your success message here
}
error:function()
{
//Your error message here
}
});
});
答案 2 :(得分:0)
如果您想在iframe中显示结果,则需要设置src
属性。
在剃刀视图中,您可以使用操作链接设置基本网址,并设置javascript:
<script type="text/javascript">
var baseUrl = '@Url.Action("CallFastPay")';
$('#myButton').click(function () {
var amount = $('#monateryAmount').val();
var url = baseUrl + '/' + amount;
$('#myFrame').attr('src', url);
});
});
</script>