JQuery验证选项不工作MVC3剃刀 [英] JQuery Validate Options not working MVC3 Razor

查看:145
本文介绍了JQuery验证选项不工作MVC3剃刀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一个简单的忽略JQuery的验证工作,我不似乎能够得到它的工作。无论我做什么,似乎不使用的选项。我已经削减了code下来,粘贴以下。感谢您的帮助。

我使用MVC3剃刀和JQuery 1.5.1

  @ code
    ViewData的(标题)=索引
    布局=〜/地区/报价/查看/共享/ _Layout.vbhtml
结束code
<脚本类型=文/ JavaScript的>
    $(文件)。就绪(函数(){
        $('#MyForm的')。验证({
            忽略:#textx
        })
    });
< / SCRIPT>
@using Html.BeginForm(指数,YourQuote,FormMethod.Post,新增功能{.ID =MyForm的})
    @<输入类型=文本ID =textx级=需要/>
    @<输入类型=提交值=拯救/>
使用完

感谢您的答复。这个例子被简化,但我真正想要做的是有一个压倒一切的规则,说忽略验证所有隐藏要素。我的页面是动态生成和删除类和添加他们回来时,父元素隐藏或显示在不适合我。

  @ code
    ViewData的(标题)=索引
    布局=〜/地区/报价/查看/共享/ _Layout.vbhtml
结束code
<脚本类型=文/ JavaScript的>
    $(文件)。就绪(函数(){
        $('#MyForm的')。验证({
            忽略:隐藏
        })
    });
< / SCRIPT>
@using Html.BeginForm(指数,YourQuote,FormMethod.Post,新增功能{.ID =MyForm的})
    @< D​​IV的风格=显示:无>
    <输入类型=文本ID =textx级=需要/>
    < / DIV>
    @<输入类型=提交值=拯救/>
使用完


解决方案

尝试删除不显眼的jQuery包容,只是包括jquery.validate。我有一个类似的问题,在某种程度上不显眼库搞砸了我的自定义设置。

I am trying to get a simple ignore working for the JQuery validate and I dont seem to be able to get it to work. No matter what I do it seems to not use the options. I have trimmed the code down and pasted below. Thanks for any help.

I am using MVC3 Razor and JQuery 1.5.1

@Code
    ViewData("Title") = "Index"
    Layout = "~/Areas/Quote/Views/Shared/_Layout.vbhtml"
End Code
<script type="text/javascript">
    $(document).ready(function () {
        $('#myform').validate({
            ignore: "#textx"
        })
    });
</script>
@Using Html.BeginForm("Index", "YourQuote", FormMethod.Post, New With {.id = "myform"})
    @<input  type="text" id="textx" class="required"/>
    @<input type="submit" value="save" />
End Using

Thanks for the reply. The example is simplified but what I really want to do is have an overriding rule which says ignore all hidden elements from validation. My page is dynamically built and removing class and adding them back in when parent elements are hidden or shown is not good for me

@Code
    ViewData("Title") = "Index"
    Layout = "~/Areas/Quote/Views/Shared/_Layout.vbhtml"
End Code
<script type="text/javascript">
    $(document).ready(function () {
        $('#myform').validate({
            ignore: ":hidden"
        })
    });
</script>
@Using Html.BeginForm("Index", "YourQuote", FormMethod.Post, New With {.id = "myform"})
    @<div style="display:none">
    <input  type="text" id="textx" class="required"/>
    </div>
    @<input type="submit" value="save" />
End Using

解决方案

Try removing the unobtrusive jquery inclusion, and just include jquery.validate. I had a similar problem and somehow the unobtrusive library screwed up my custom defined settings

这篇关于JQuery验证选项不工作MVC3剃刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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