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?

Daniel
  • 9,491
  • 12
  • 50
  • 66
ramin_rp
  • 321
  • 1
  • 4
  • 14
  • Have a look at this question http://stackoverflow.com/questions/4406291/jquery-validate-unobtrusive-not-working-with-dynamic-injected-elements – ste-fu May 24 '15 at 12:44
  • @ste-fu i read this question and answers, but I could not solve my problem – ramin_rp May 24 '15 at 13:04

2 Answers2

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);
    });
}
Daniel
  • 9,491
  • 12
  • 50
  • 66
Igor
  • 176
  • 7
0

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

ramin_rp
  • 321
  • 1
  • 4
  • 14