通过动态加载的局部视图进行无干扰的验证 [英] Unobtrusive validation with dynamically loaded partial view
本文介绍了通过动态加载的局部视图进行无干扰的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在点击按钮加载partail视图
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"));
}
}
验证不适用于ajax请求加载的部分视图.但是,它可以与@Html.Partial("ChangePassword", Model.changepassword)
Validation is not working on partial view loaded by ajax request. However it works with @Html.Partial("ChangePassword", Model.changepassword)
任何帮助;
推荐答案
您必须在load
的回调函数中调用parse函数:
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"));
});
}
}
现在,您正在调用parse函数,然后再加载任何内容.
Right now, you are calling the parse function before any content could be loaded.
这篇关于通过动态加载的局部视图进行无干扰的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文