JQuery的模式对话框的形式验证 [英] JQuery modal box form validation

查看:93
本文介绍了JQuery的模式对话框的形式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用一个视图中创建为我的具体项目的对象,但现在我有这个适应其他要求,如创建这个对象必须集成在创造一个又一个的。问题是,这个对象必须在开始创建另外一个,而且做起来会坡平了,用jQuery一个模式对话框与形式来创建它的方式之前创建。我必须适应建立和它工作正常,除了验证消息。它是在控制器作出这样的:

I was using a view to create an object for my specific project, but now I have to adapt this to another requirements, such as the creation of this object must be integrated in the creation of another one. The thing is, that this object must be created before starting to create the other one, and the way of doing it will be poping up a modal dialog box with JQuery with the form to create it. I've got to adapt the creation and it works fine, except for the validation messages. It is made in the controller like :

if (not.NotName.Trim().Length == 0)
{
    ModelState.AddModelError("NotName", "Name is required");
}
if (_notification.checkIfExists(not.NotName, not.NotRecID))
{
    ModelState.AddModelError("NotName", "Notification already exists");
}

和以普通视图之前,它工作得很好,但现在我不能像我一样得到验证消息。你怎么能得到通过控制器的模式对话框抛出这个验证消息?因为现在我在的形式,以获得它不会出现错误犯了一个错误的目的。我看到显示在网站上的错误,因为我已经看到它在Firebug的,但它不会出现在我的模型框。我怎样才能检索到的错误?你知道的任何教程,可以帮助我?

And before with a normal view it worked fine, but now I'm not able to get the validation messages as I did. How can you get this validation messages thrown by the controller in the Modal Box? Because now when I made a mistake on purpose in the form in order to get the error it doesn't appear. I've seen the error is displayed in the site, because I've seen it on firebug, but it doesn't appear in my model box. How can I retrieve this errors? Do you know any tutorial that could help me with this?

JavaScript方法是:

The javascript method is:

function newNotificationModalBox() {
    $("#newNotificationModalBox").dialog("destroy");

    $("#newNotificationModalBox").dialog({
        modal: true,
        open: function(event, ui) {
            //resetNotificationForm();
        },
        buttons: {
            'Create': function() {
                var name = document.getElementById("NotName").value;
                var status = document.getElementById("NotificationStatus").value;
                var replace = document.getElementById("ReplaceYes").checked;
                var notificationToReplace = document.getElementById("ReplaceNotificationID").value;
                var dataString = 'NotName=' + name + '&NotificationStatus=' + status + '&Replace=' + replace + '&ReplaceNotificationID=' + notificationToReplace;
                $.ajax({
                    type: "POST",
                    url: "/Suspension/CreateNotification",
                    data: dataString
                    });
                var list = document.getElementById("sNotification").options.length;
                loadNotifications("/SearchSuspensions/LoadNotifications/", "A", "sNotification", "pNotificationName");
                alert('submitting form');
                //alert(document.getElementById("sNotification").options.length);
                if (list != document.getElementById("sNotification").options.length) {
                    $(this).dialog('close');
                    setTimeout('selectNotificationCreated();', 100);
                    alert('Notification succesfully created');
                }
                else {
                    alert('Error');
                }
            },
            'Cancel': function() {
                $(this).dialog('close');
            }
        }
    });

}

感谢您

推荐答案

一个possibliity是创建呈现形式的局部视图。然后创建一个将呈现局部视图的操作。现在,使用AJAX加载的局部视图进入模式。当您过帐,模态将发布通过AJAX的形式。当后返回时,你要么是成功还是应该用错误的形式返回给您,让您重新加载模态的形式和errormessages。

A possibliity is to create a partial view that renders the form. Then Create an action that will render the partial view. Now using AJAX load the partial view into the modal. When you post, the modal will post the form via AJAX. When the post returns, you will either be successful or it should return the form back to you with the errors, allowing you to reload the form and errormessages in the modal.

这篇关于JQuery的模式对话框的形式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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