【问题标题】:Where is it best to add a confirmation dialog popup最好在哪里添加确认对话框弹出窗口
【发布时间】:2013-05-03 05:48:14
【问题描述】:

我正在使用ASP.NET MVC 4 和最新版本的jQuery UIFluent Validation 来处理我的服务器端验证。

我正在尝试让jQuery dialog 在提交表单之前用作确认弹出窗口。用户应单击“是”提交表单或单击“取消”以留在表单上。

我已经用 Google 搜索并尝试了给出的示例,但我无法让它发挥作用。我试过在按钮的点击事件上这样做,没有用。现在我正在尝试将其添加到表单提交中。

我的 HTML 标记:

<button id="SaveButton" type="submit">Save</button>

<div id="dialog-confirm" title="Save Customer?">
     <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure you want to save this customer?</p>
</div>

我的 jQuery 代码:

$(document).ready(function () {
     $('form').submit(function () {
          $('#dialog-confirm').dialog('open');
          return false;
     });

     $('#dialog-confirm').dialog({
          autoOpen: false,
          resizable: false,
          modal: true,
          buttons: {
               'Save': function () {
                    $('form').sumbit();
               },
               Cancel: function () {
                    $(this).dialog('close');
               }
          }
     });
});

我使用上述方法得到的错误是:

Object doesn't support this property or method

...它在$('form').sumbit(); 上中断

如何让它正常工作?最好在哪里添加这个?在按钮上还是在提交表单时?两者都有?

注意:答案需要基于jQueryjQuery dialog 控件。

【问题讨论】:

  • 这不是函数sumbit;你在submit()之后吗?还值得注意的是,jQuery UI 对话框是非阻塞的……
  • 为什么不用asp.net mvc 4的验证?您可以在对话框中添加部分视图,然后使用 mvc 4 的验证表单。

标签: jquery asp.net asp.net-mvc asp.net-mvc-3 jquery-ui


【解决方案1】:

试试这个:

$('#dialog-confirm').dialog({
      autoOpen: false,
      resizable: false,
      modal: true,
      buttons: [
                {
                    text : 'Save',
                    click : function () {
                        $('form').submit();
                    }
                },
                {
                    text : 'Cancel',
                    click : function () {
                         $(this).dialog('close');
                    }
                }
            ]
      }
 });

【讨论】:

    【解决方案2】:

    你可以试试这个:在视图中:@Html.ActionLink("Delete", "DeleteEmp", new { id = item.Id }, new { onclick = " return DeleteConfirm()" })

    在脚本中:function DeleteConfirm(){ if (confirm("Are you sure to delete record")) return true;否则返回假; }

    在控制器中:public ActionResult DeleteEmp(int id) { var empDelete = (from emp in dbml.M_Employees where emp.Id == id select emp).Single(); dbml.M_Employees.DeleteOnSubmit(empDelete); dbml.SubmitChanges(); return RedirectToAction("索引"); }

    【讨论】:

    • 答案需要与 jQuery 对话框控件有关。
    猜你喜欢
    • 2011-11-21
    • 2012-01-04
    • 2015-11-11
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多