这是我的示例代码 - 它与Bank WithDraw方法有关的计算..如果用户提取为负值,则显示对话框(是/否)选项...
[HttpPost]
public ActionResult withdraw()
{
if(Sum<0)
{
Code For Dialogue Box;
if(Yes)
//Do
else
//Exists
}
return View();
}
答案 0 :(得分:0)
控制器:
public ActionResult withdraw()
{
if(Sum<0)
{
Code For Dialogue Box;
if(Yes)
ViewBag.Result="true";
else
ViewBag.Result="false";
}
return View();
}
我假设你在布局或页面中有jquery,查看:
<script>
$(document).ready(function(){
if(@ViewBag.Result="true"){
alert("true");
}
})
</script>
答案 1 :(得分:0)
我建议在按钮点击或其他任何内容上调用jquery / js函数,如下图,
$('#withdrawBtn').click(function(){
//Take the withdraw fields value. Let's say it's a text box with ID myWithdrawTextBox
if($('#myWithdrawTextBox').val() > 0)
{
//Post to your server. I mean call your Action Method
}
else
alert('Please enter correct amount');
})
希望有所帮助:)