问题
I'm loading partail view on button click
function loadview(ele) {
if (ele == 'account') {
$('#updateprofile').load('@Url.Action("UpdateProfile", "Account")');
$.validator.unobtrusive.parse($("#updateprofile"));
}
if (ele == 'password') {
$('#changepassword').load('@Url.Action("ChangePassword", "Account")');
$.validator.unobtrusive.parse($("#changepassword"));
}
}
Validation is not working on partial view loaded by ajax request. However it works with @Html.Partial("ChangePassword", Model.changepassword)
Any help;
回答1:
You have to call the parse function in the callback function of load
:
function loadview(ele) {
if (ele == 'account') {
$('#updateprofile').load('@Url.Action("UpdateProfile", "Account")', function () {
$.validator.unobtrusive.parse($("#updateprofile"));
});
}
if (ele == 'password') {
$('#changepassword').load('@Url.Action("ChangePassword", "Account")', function () {
$.validator.unobtrusive.parse($("#changepassword"));
});
}
}
Right now, you are calling the parse function before any content could be loaded.
来源:https://stackoverflow.com/questions/22046168/unobtrusive-validation-with-dynamically-loaded-partial-view