C# 如何在控制器中写入确认对话框代码?对于Asp.net MVC
这是我的示例代码-它与银行取款方法类似。。如果用户撤消为负值,则显示一个对话框(是/否)选项C# 如何在控制器中写入确认对话框代码?对于Asp.net MVC,c#,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,这是我的示例代码-它与银行取款方法类似。。如果用户撤消为负值,则显示一个对话框(是/否)选项 [HttpPost] public ActionResult withdraw() { if(Sum<0) { Code For Dialogue Box; if(Yes) //Do else //Exists }
[HttpPost]
public ActionResult withdraw()
{
if(Sum<0)
{
Code For Dialogue Box;
if(Yes)
//Do
else
//Exists
}
return View();
}
[HttpPost]
公众行动结果撤回()
{
如果(总和控制器:
public ActionResult withdraw()
{
if(Sum<0)
{
Code For Dialogue Box;
if(Yes)
ViewBag.Result="true";
else
ViewBag.Result="false";
}
return View();
}
public ActionResult撤回()
{
如果(Sum@Euphoria的回答是实现目标的一种方法。但是,当我可以检查提取值并在客户端本身显示一条警告消息时,为什么我要调用服务器呢
我建议在单击按钮或其他类似的操作时调用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');
})
希望能有所帮助:)您正在混合关注点。显示对话框是由视图完成的,控制器与此无关使用JavaScript处理它谢谢您明确我的概念..您的时间:)非常感谢..我将尝试:)这是工作发现:)
$('#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');
})