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

╄→尐↘猪︶ㄣ 提交于 2019-11-29 09:45:09
ThunD3eR

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!