4 MVC客户端验证工作不适合其使用Ajax加载表单 [英] MVC 4 client side validation not working for the form which is loaded using Ajax

查看:92
本文介绍了4 MVC客户端验证工作不适合其使用Ajax加载表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个管理在用户点击链接和页面对应的 PartialView ,包含的网页表单然后里面特定的 DIV 的加载管理使用Ajax网页。

I have an Admin page in which the user clicks on links and the corresponding PartialView, containing a web form is then loaded inside a particular div on the Admin page using Ajax.

所有的

"~/Scripts/jquery-2.0.3.js",
"~/Scripts/jquery.unobtrusive-ajax.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate.unobtrusive.js"

是在管理页中引用而当 PartialView 加载时,的 jQeury客户端验证的赢得了科技工作。

are referenced within the Admin page and when the PartialView is loaded, the jQeury client side validation won't work.

但是当我引用这些脚本中的 PartialView ,一切都运行得很好,但我不打算这样做的每个 PartialView ,因为它们有很多,每一次每一个负载,至少有两个那些的.js文件必须从服务器请求的再次

but when I reference those scripts within the PartialView, everything works just fine but I don't intend to do this for each PartialView because they are numerous and each time each one loads, at least two of those .js files must be requested from the server again.

有什么办法,我可以有我的父母里面那些脚本(管理)页没有这个问题?

Is there any way I can have those scripts inside my parent (Admin) page without this issue ?

推荐答案

您需要这对你的部分看法每一个:

You need this on each one of your partial views:

$(document).ready(function () {

    $.validator.unobtrusive.parse("#YourFormID");

});

基本上验证未绑定的动态呈现形式......

Basically the validation is not bound on the dynamically rendered form...

这篇关于4 MVC客户端验证工作不适合其使用Ajax加载表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆