如何在验证事件上显示弹出窗口?

发布于 2024-12-19 08:13:40 字数 408 浏览 0 评论 0原文

看来我一直在努力寻找一个好的解决方案来解决我的问题。我们有一个 MVC 3 应用程序和一个表单,我们使用数据注释对其进行验证。在电子邮件字段中,我有一个 RemoteAttribute 来检查电子邮件是否是唯一的。 我需要实现这个:

  1. 如果电子邮件是唯一的 - 一切都很好,我们不需要做任何事情。

  2. 如果电子邮件不是唯一的 - 我们需要显示一个带有是\否选项的模式弹出窗口。如果用户 选择“是” - 该字段将有效,如果“否” - 字段无效,我们需要显示一条弹出消息。

不幸的是,我找不到这个

小更新的任何好的解决方案:我不想验证整个表单:仅验证电子邮件字段。在这种情况下,无法真正理解如何使用 jQuery 或 ValidationSummary 中的 form.Validate

It looks like I'm stuck trying to find a good solution for my issue. We have an MVC 3 application and a form, which we validate using Data Annotations. On Email field I have a RemoteAttribute which checks, that Email is unque.
The this I need to implement:

  1. If Email is unique - everything is ok, we don' tneed to do anything.

  2. If Email is not unque - we need to show a modal popup window with a yes\no choice. If user
    chooses "yes" - the field will be valid, if "no" - field is invalid and we need to show a popup message.

Unfortunatelly, I couldn't find any good solution for this

Small update: I don't want to validate the whole form: only the Email field. In this case, can't really understand how to use form.Validate from jQuery or ValidationSummary

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

银河中√捞星星 2024-12-26 08:13:40

试试这个:

在您的视图中为 ModelState: 的错误创建容器,

<div id="errorPopUp" style="display:none">
    @Html.ValidationSummary()
</div>

并在视图的脚本部分中:

$(document).ready(function () {
    if(@:!ModelState.IsValid) {
            $('#errorPopUp').dialog({
                resizable: false,
                width: 400,
                modal: true,
                autoOpen: true
            });
        }
    }
}

Try this:

In your view create container for errors form ModelState:

<div id="errorPopUp" style="display:none">
    @Html.ValidationSummary()
</div>

and in script section of your view:

$(document).ready(function () {
    if(@:!ModelState.IsValid) {
            $('#errorPopUp').dialog({
                resizable: false,
                width: 400,
                modal: true,
                autoOpen: true
            });
        }
    }
}
萌能量女王 2024-12-26 08:13:40

您可以使用 jquery validate 来执行此操作:

            var frm = $('#formData');

            frm.validate();
            if (frm.valid()) {
            // do nth or submit the form
            }
            else{
                 // Declare a dialog
                 var $dialog = $('#dialogdiv').dialog({
                     autoOpen: false,
                     modal: true
                 });
                 // Declare the yes/no options
                 ....
           }

这是您需要的吗?

希望这有帮助:)

You can use jquery validate to do this:

            var frm = $('#formData');

            frm.validate();
            if (frm.valid()) {
            // do nth or submit the form
            }
            else{
                 // Declare a dialog
                 var $dialog = $('#dialogdiv').dialog({
                     autoOpen: false,
                     modal: true
                 });
                 // Declare the yes/no options
                 ....
           }

Is this the thing you need?

Hope this help :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文