Unobtrusive validation not working on dynamically-added partial view

后端 未结 2 1026
一个人的身影
一个人的身影 2020-11-28 04:19

I am currently facing a problem with validation after dynamically adding content.

I have a view strongly typed to a model (Order). This Order can have m

2条回答
  •  忘掉有多难
    2020-11-28 05:10

    What worked for me was to re-apply the validator after the call to load the partial view. In my case, I'm using $.post().then() but you could do something similar with a .always() callback of an AJAX call.

    $.post(url, model, function (data) {
        //load the partial view
        $("#Partial").html(data);
    }).then(function () {
        $("form").each(function () { $.data($(this)[0], 'validator', false); });
        $.validator.unobtrusive.parse("form");
    });
    

提交回复
热议问题