How to setup MVC 5 unobtrusive validation correctly when appending the form from an AJAX call?

前端 未结 1 1466
不知归路
不知归路 2020-12-17 17:36

I have googeld about this issue and I have checked my web.config, bundleconfig and my layout which look like this: web.config:


    

        
相关标签:
1条回答
  • 2020-12-17 18:14

    After some time I figured this out.

    I was appending this form from an AJAX call which returned a partial view.

    I found the answer here

    apperently when adding dynamic data like this you first have to strip the form of 'validator' and 'unobtrusiveValidation'and then call the $.validator.unobtrusive.parse function on the form, like so:

    var form = $("#main_div").closest("form");
    form.removeData('validator');
    form.removeData('unobtrusiveValidation');
    $.validator.unobtrusive.parse(form);
    

    A more detailed explenation can be found here

    0 讨论(0)
提交回复
热议问题