I came across this scenario whereby my main View uses Ajax posts to retrieve PartialViews and delivers the markup of the PartialView into my View. I use the jQuery validation framework to implement client side unobstrusive validation.

When I tried to validate my form that had been loaded into the page via an Ajax call, the validation did not appear to be working, my form simply posted. As it turns out, the unobstrusive jQuery validator library parses the markup of a page after it has finished loading for all the validation rules on the page. The result is, jQuery doesn’t know that the dynamically added markup has any validation rules resulting in no validation errors being thrown on post.

Solution

Luckily there is a method that is publicly accessible in the unobstrusive jQuery library which you can call, which will force the parser to scan the markup you just loaded. To do this you need to add the following code to the PartialView (or other dynamically loaded content)

12345
//this code goes in your partialview
$(function(){
//allow the validation framework to re-prase the DOM
jQuery.validator.unobtrusive.parse();
});
view rawgistfile1.jsThis Gist brought to you by GitHub.       

Then in your parent page you can handle the form submission and check the form is valid like this;

12345678
//then in your parent page handle the form submission
$(function(){
$("#SubmitButton").click(function(){
if (!$("#Form1").valid()){
return false;
}
});
});

MVC client validation after PartialView loaded via Ajax MVC3中 弹出 Dialog时候 提交的时候 使用 Jquery 不验证 form表单 的解决办法的更多相关文章

  1. Jquery来对form表单提交(mvc方案)

    来自:http://www.cnblogs.com/lmfeng/archive/2011/06/18/2084325.html 我先说明一下,这是asp.net mvc 里面的用法, Jquery来 ...

  2. Easyui Ajax验证Form表单。。。

        今天做项目用到easyui Ajax验证表单.本想自定义一个easyui的验证,查资料发现easyui 自带了一个通用的验证!见以下下截图. 后台返回值 true验证通过,返回false验证失 ...

  3. 【jQuery】将form表单通过ajax实现无刷新提交

    //将form转换为AJAX提交 function ajaxSubmit(url,frm,fn){ var dataPara=getFormJson(frm); $.ajax({ url:url, t ...

  4. Ajax模拟Form表单提交,含多种数据上传

    ---恢复内容开始--- Ajax提交表单.使用FormData提交表单数据和上传的文件(这里的后台使用C#获取,你可以使用Java一样获取) 有时候前台的数据提交到后台,不想使用form表单上传,希 ...

  5. Jquery通过Ajax方式来提交Form表单

    今天刚好看到Jquery的ajax提交数据到服务器的方法,原文是: 保存数据到服务器,成功时显示信息. jQuery 代码: $.ajax({ type: "POST", url: ...

  6. MVC中Form表单的提交

    概述 Web页面进行Form表单提交是数据提交的一种,在MVC中Form表单提交到服务器.服务端接受Form表单的方式有多种,如果一个Form有2个submit按钮,那后台如何判断是哪个按钮提交的数据 ...

  7. ajax传递数组、form表单提交对象数组

    在JSP页面开发中,我们常常会用到form表单做数据提交,由于以前一直只是使用form表单提交单个对象,只要表单文本域的name值和接收的对象的属性名一致,那么传值就没有什么问题.不过,在前几天的开发 ...

  8. Django学习系列之Form表单结合ajax

      Forms结合ajax Forms的验证流程: 定义用户输入规则的类,字段的值必须等于html中name属性的值(pwd= forms.CharField(required=True)=<i ...

  9. form表单和ajax表单提交(Html.BeginForm()、Ajax.BeginForm())的差别

    有如下几种区别: 1. Ajax在提交.请求.接收时,都是异步进行的,网页不需要刷新: Form提交则是新建一个页面,哪怕是提交给自己本身的页面,也是需要刷新的: 2. A在提交时,是在后台新建一个请 ...

随机推荐

  1. LocalContainerEntityManagerFactoryBean

    http://doc.okbase.net/liuyitian/archive/109276.html

  2. 关于xcode6打包以及上线前企业部署测试的说明 --转自张诚教授微博

    xcode6如何打包 首先clean然后点击归档 点击打包之后保存 点选第一个以后检查相关证书签名 那么我们开发完以后,在上线前如何给别人测试 有2种方法 1.使用299美金的企业开发者账号搭建企业部 ...

  3. python eval函数

    eval()函数十分强大,官方demo解释为:将字符串str当成有效的表达式来求值并返回计算结果. 可以把字符串转为list.tuple .dict  等数据类型 1.把字符串转为字典 ####### ...

  4. DataGridView自动行号

    最近又用了一下DataGridView控件,需要显示行号,我们知道在.net中DataGridView控件默认是不显示行号(数据的记录行数)的,后来通过查资料发现可以在DataGridView控件的R ...

  5. AT&T 和 Intel 汇编语法的主要区别

    转自AT&T 和 Intel 汇编语法的主要区别 作为一个爱折腾的大好青年,补番之余还要补一些 Linux 下的基础,比如 GDB 的正确使用方法.但无论是看 gdb 还是 gcc -S 里的 ...

  6. easyui源码翻译1.32--ComboBox(下拉列表框)

    前言 扩展自$.fn.combo.defaults.使用$.fn.combobox.defaults重写默认值对象.下载该插件翻译源码 下拉列表框显示一个可编辑文本框和下拉式列表,用户可以选择一个值或 ...

  7. 如何让centos6.5在vm11里上网,连接网络?

    如何让centos在vm里连接网络?步骤有3,方可解决: 1.配置vm的虚拟网络编辑器 2.配置虚拟机centos 3.设置centos的ip地址 一.配置vm的虚拟网络编辑器

  8. eCos中断模型

    http://blog.csdn.net/chychc/article/details/8313458 http://www.cnblogs.com/RandyQ/archive/2013/04/14 ...

  9. QVariant实质 (类似 C#中的装箱拆箱)

    QVariant是一种可以存储不同类型的数据结构,在很多场合这是很有用得为了达到这种目的,可以想象,该对象应该存储对象的类型信息,数据信息以及其他辅助详细考虑用途,这种对象必须支持对不同对象的存储,对 ...

  10. 【Xamarin挖墙脚系列:IOS-关于手机支持的屏幕方向】

    原文:[Xamarin挖墙脚系列:IOS-关于手机支持的屏幕方向] 设置支持的屏幕方向有两个级别,一个是app级别的,另一个是viewController级别的. app 级别的可以在[target] ...