如何在MVC3中在客户端动态启用控件验证? [英] How to enable validation for controls dynamically in client side in MVC3?

查看:87
本文介绍了如何在MVC3中在客户端动态启用控件验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
在我目前的MVC3项目中,我正在构建一个包含大量文本框的页面,要求只有当用户在任何一个字段中输入值时才能在控件上启用验证。如果一个文本框中有值,则用户应在每个文本框中输入值。在MVC3中,为我的模型属性指定[Required]属性会强制对所有控件进行验证,并且始终无法满足我的要求。所以我需要检查是否有任何文本框在客户端输入值,然后发布这些字段的必需验证应该启用..



请一些帮助我这一周..这个问题的一周搜索使我的头发脱离我的头皮:(

解决方案

你可以做这样的事情



 


#btnSaveData)。点击( function (event){
if


' #name') .val()。length> 0
{
if

Hi In my current project in MVC3, I am building a page having bunch of textbox, the requirement is to enable the validation on the controls only if the user enters value in any one of the field. If there is a value in one text box then the user should enter value in every text box. In MVC3, specifying "[Required]" attribute to my model properties enforce the validation to all controls and at all time, defeating my requirement. So i would need to check if any text box has value entered in client side, post then the Required validation for these fields should be enabled..

Please some one help me with this.. The week long search for this problem makes my hair falling out of my scalp :(

解决方案

You can do such thing


("#btnSaveData").click(function (event) { if (


('#name').val().length > 0) { if (


这篇关于如何在MVC3中在客户端动态启用控件验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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