C# 视图没有';无法从控制器返回
我想通过onclick函数将数据传送到下一页。所有数据都通过给定参数携带,但它不会从控制器返回视图。请帮帮我。我被困在这里两天这是我的学校项目 单击按钮:C# 视图没有';无法从控制器返回,c#,jquery,ajax,asp.net-mvc,C#,Jquery,Ajax,Asp.net Mvc,我想通过onclick函数将数据传送到下一页。所有数据都通过给定参数携带,但它不会从控制器返回视图。请帮帮我。我被困在这里两天这是我的学校项目 单击按钮: <div class="row"> <div class="col-sm-4"></div> <button class='btn bg-blue next' onclick="checkamt(@Model.TotalAmt)">Next</button> <
<div class="row">
<div class="col-sm-4"></div>
<button class='btn bg-blue next' onclick="checkamt(@Model.TotalAmt)">Next</button>
</div>
阿贾克斯:
功能检查金额(e){
var amount=@ViewBag.CurrentAmt;
如果(金额
视图:
您拥有总计@ViewBag.CurrentAmt点数
删除ajax函数并执行此操作
window.location.href = "@Url.Action("ComfirmPay", "Home")" + "?e=" + e + "&taxtype=" + taxtype + "¤tamt=" + currentamt
帖子上的评论解释了为什么你所做的事情不起作用 我认为您不需要ajax调用。您可以按如下方式使用
window.location.href
function checkamt(e) {
var amount = @ViewBag.CurrentAmt;
if (amount < e) {
window.location.href = 'http://localhost:22822/Home/PayTax';
}
else {
window.location.href = '/Home/ComfirmPay?e='+e+'&taxtype='+taxtype+'¤tamt='+currentamt;
}
}
在ajax调用中添加错误部分,并检查返回的错误。使用ajax时,返回视图不起作用。如何修复它,先生?您可以使用returnPartialView();您在
操作ComfirmPay
中使用任何“方法”,如get
或post
?
<div class="col-md-9 col-xs-9">
<p class="text-muted">You have total <b class="text-green">@ViewBag.CurrentAmt</b> points</p>
</div>
window.location.href = "@Url.Action("ComfirmPay", "Home")" + "?e=" + e + "&taxtype=" + taxtype + "¤tamt=" + currentamt
function checkamt(e) {
var amount = @ViewBag.CurrentAmt;
if (amount < e) {
window.location.href = 'http://localhost:22822/Home/PayTax';
}
else {
window.location.href = '/Home/ComfirmPay?e='+e+'&taxtype='+taxtype+'¤tamt='+currentamt;
}
}
public ActionResult ComfirmPay(string e, string TaxType, string CurrentAmt)
{
ViewBag.TotalAmt = e;
ViewBag.CurrentAmt = CurrentAmt;
ViewBag.TaxType = TaxType;
return View();
}