Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在控制器中写入确认对话框代码?对于Asp.net MVC_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

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');
})