简体   繁体   English

如何在JQuery弹出窗口中的文本框上实现所需的验证

[英]How to Implement Required Validation on Text Boxes in JQuery Popup

I have a JQuery Popup which includes some text boxes. 我有一个包含一些文本框的JQuery Popup。 I have applied Required validation on text boxes from Model but it doesn't work in popup. 我已经在模型的文本框中应用了必填验证,但是在弹出窗口中不起作用。 Without popup, validation works accurately. 没有弹出窗口,验证就可以正确进行。 Please help in this regard that is there any special syntax in JQuery popup for controls validations.Here is my popup code.. 在这方面请帮忙,JQuery弹出窗口中是否有用于控件验证的特殊语法。这是我的弹出代码。

var dialogBox = $("#mc-dialog");
        $('#dvMCodes').on('click', '#tblMC .modalEdit', function (event) {

            event.preventDefault();
            var actionURL = $(this).attr('href');

            //alert(actionURL);

            $(dialogBox).dialog({
                autoOpen: false,
                resizable: false,
                title: 'Edit',
                modal: true,
                show: "blind",
                width: 'auto',
                hide: "blind",
                open: function (event, ui) {
                    $(this).load(actionURL, function (html) {
                        $('form', html).submit(function () {
                            $.ajax({
                                url: this.action,
                                type: this.method,
                                data: $(this).serialize(),
                                success: function (res) {
                                    if (res.success) {
                                        $(dialogBox).dialog('close');
                                    }
                                }
                            });
                            return false;
                        });
                    });
                }
            });

            $(dialogBox).dialog('open');
        });

and here is my Model's code 这是我模型的代码

        [Required(ErrorMessage = "*")]
        public string Code { get; set; }
        public string Description { get; set; }

and here is HTML Code 这是HTML代码

@if (IsEditMode)
                {
                    @Html.LabelFor(m => m.Code)
                    @Html.TextBoxFor(m => m.Code, new { @readonly = "readonly" })
                }
                else   
                {
                    @Html.LabelFor(m => m.Code)
                    @Html.TextBoxFor(m => m.Code)
                    @Html.ValidationMessageFor(m => m.Code)
                }

            </li>

            <li>
                @Html.LabelFor(x => x.Description)
                @Html.TextAreaFor(x => x.Description)
            </li>
$(this).submit(function (event) {

        if ($.trim($('#code').val()).length == 0) {
            alert('Please enter value for Code');
            event.preventDefault();
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM