3

I have a partial view for my login dialog content.

In my page i have

<input type="button" value="Open" onclick=" OpenDialog() "/>

<div id="dialog">

</div>

Here is the code that is on the page for load partial view to dialog:

<script type="text/javascript">

    $(document).ready(function() {

        $('#dialog').dialog({
            autoOpen: false,
            width: 400,
            height: 300,
            closeOnEscape: true,
            closeText: "Close",
            modal: true,
            resizable: false,
            title: "login",
            open: function () {
                $(this).load('@Url.Action("login", "Home")');
            }
        });
    });

    function OpenDialog() {

        var form1 = $("#dialog").removeData("validator").removeData("unobtrusiveValidation");
        $.validator.unobtrusive.parse(form1);

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

</script>

But client side validation for login form not work. What is wrong in my code?

2

2 Answers 2

4

You must run $.validator.unobtrusive.parse(form1); after load form. Change your open handler to

open: function () {
    var $this = $(this);
    $this.load('@Url.Action("Login", "Account")', function () {
        $.validator.unobtrusive.parse($this);
    });
}
0

I moved $.validator.unobtrusive.parse(selector); to partial view and problem solved.

Not the answer you're looking for? Browse other questions tagged or ask your own question.