如何在MVC控制器中创建确认框? [英] How to create the confirm box in mvc controller?

查看:102
本文介绍了如何在MVC控制器中创建确认框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在mvc控制器中创建确认框吗?使用此是"或否"值,我需要在控制器中执行操作.我们该怎么做?

I need to create the confirm box in mvc controller?. Using this 'yes' or 'no' value I need to perform the action in my controller. How we do that?

示例代码:

    public ActionResult ActionName(passing value)
        {
             // some code 
             message box here
               if (true)
                     { true code}
              else { else code}
       }

推荐答案

您没有在Controller中创建确认框,但是在视图中使用JQuery对话框创建了确认框. Controller已经在服务器内部,因此您没有用户交互. 另一方面,视图"是用户选择选项,键入信息,单击按钮等的地方. 您可以拦截按钮的单击以显示该对话框,并且仅在单击选项是"时才提交帖子.

You dont create confirm box in a Controller, but yes in a View, using JQuery Dialog. The Controller is already inside the server, so you don't have user interactions there. Your View, in the other hand, is the place where the user will choose options, type information, click on buttons etc... You can intercept the button click, to show that dialog, and only submit the post when the option "Yes" gets clicked.

JQuery对话框需要页面中引用的 jquery.js jquery-ui.js jquery.ui.dialog.js 脚本.

JQuery Dialog requires jquery.js, jquery-ui.js, jquery.ui.dialog.js scripts referenced in your page.

示例:

$(function(){
    $("#buttonID").click(function(event) {
        event.preventDefault();
        $('<div title="Confirm Box"></div>').dialog({
            open: function (event, ui) {
                $(this).html("Yes or No question?");
            },
            close: function () {
                $(this).remove();
            },
            resizable: false,
            height: 140,
            modal: true,
            buttons: {
                'Yes': function () {
                    $(this).dialog('close');
                    $.post('url/theValueYouWantToPass');

                },
                'No': function () {
                    $(this).dialog('close');
                    $.post('url/theOtherValueYouWantToPAss');
                }
            }
        });
    });
});

这篇关于如何在MVC控制器中创建确认框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆