MVC3验证输入'不等于对“ [英] mvc3 validate input 'not-equal-to'

查看:168
本文介绍了MVC3验证输入'不等于对“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的形式有引导什么输入用户(而不是使用标签),默认的帮手文本输入。这使得验证棘手,因为输入值不能为null。

My forms have inputs with default helper text that guides the user on what to enter (rather than using labels). This makes validation tricky because the input value is never null.

如何延长不显眼的验证来处理呢?该形式不应该是有效的,如果在名称输入等于请输入你的名字......

How can I extend unobtrusive validation to handle this? The form shouldn't be valid if the Name input is equal to "Please enter your name..."

我开始阅读关于审定适配器布拉德·威尔逊的博客文章,但我不敢肯定这是否是正确的方式去?我需要能够验证对视场不同的默认值。

I started reading Brad Wilson's blog post on validation adapters, but I'm not sure if this is the right way to go? I need to be able to validate against different default values depending on the field.

感谢

推荐答案

那是正确的方式去。您应该实现自己的属性附加伤害和实施 IClientValidatable

Yes thats the right way to go. You should implement your own atribute and implement IClientValidatable.

您可能也有最初设置为所需布尔值false 作为一个隐藏表单域。当用户改变文本框,将其设置为true。

You could also have a required boolean value set initially to false as a hidden form field. When the user changes the textbox, set it to true.

这篇关于MVC3验证输入'不等于对“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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