[ACCEPTED]-Unobtrusive validation not working on dynamically-added partial view-dynamically-generated
Accepted answer
Ok, I am going to start over with a new 4 answer here.
Before you call $.validator.unobtrusive.parse
, remove the 3 original validator and unobtrusive validation 2 from the form like so:
var form = $("#main_div").closest("form");
form.removeData('validator');
form.removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(form);
This same answer is 1 documented here.
What worked for me was to re-apply the validator 3 after the call to load the partial view. In 2 my case, I'm using $.post().then()
but you could do something 1 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");
});
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.