【问题标题】:Unobtrusive validation with dynamically loaded partial view使用动态加载的局部视图进行不显眼的验证
【发布时间】:2014-02-26 23:49:24
【问题描述】:

我正在点击按钮加载部分视图

 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)

任何帮助;

【问题讨论】:

  • dynamically created html validation 是什么意思?
  • 验证不适用于动态创建的 html

标签: asp.net-mvc-4 unobtrusive-validation


【解决方案1】:

你必须在load的回调函数中调用parse函数:

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 函数。

【讨论】:

    猜你喜欢
    • 2012-03-08
    • 1970-01-01
    • 2011-11-02
    • 2013-12-28
    • 1970-01-01
    • 2012-09-09
    • 2021-02-21
    • 1970-01-01
    相关资源
    最近更新 更多