验证一个属性,如果另一个属性对MVC 3 / jQuery的验证值 [英] Validating a property if another property has a value on MVC 3/jQuery Validator

查看:111
本文介绍了验证一个属性,如果另一个属性对MVC 3 / jQuery的验证值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能在一个属性Prop2只有在为prop1是真的吗?使用需要确认

how can I use a Required Validation in a property Prop2 only if the Prop1 is true?

Ex:
public bool Prop1 { get; set; }

[Required] // I need this validation only if the Prop1 is true.
public string Prop2 { get; set; }

你知道吗?我需要在客户端和服务器端。
谢谢

Any idea? I need on client and server side. Thanks

推荐答案

您可以编写一个自定义验证器做这个工作。

You can write a custom validator do to this job.

让我知道,如果你需要帮助做到这一点。

Let me know if you need help to do it.

这篇关于验证一个属性,如果另一个属性对MVC 3 / jQuery的验证值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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