2016-04-08 15 views
0

私はFoolproofの検証を使用しています。MVCサーバー側の検証

を呼び出すとき[RequiredIfTrue( "CommonUseStatus")]

誰にでもできるReqiuredIfAttributeはSystem.NullReferenceExceptionを与えます。 CommonUseInfoにはCommonUseStatusプロパティがないため、 です。 この方法でこの属性を使用するにはどうすればよいですか?

public class FoundationCode : SpatialEntity 
{ 
    public bool CommonUseStatus {get; set;} 
    public string FullFoundationCode { get; set; } 
    public string ProvinceCode { get; set; } 
    public string DistrictCode { get; set; } 
    public bool FoundationOwner { get; set; } 
    public virtual CommonUseInfo CommonUseInfo { get; set; } 
} 


public class CommonUseInfo : BaseEntity 
{ 
    public int CommonUseSchool { get; set; } 
    **[RequiredIfTrue("CommonUseStatus")]** 
    public DateTime CommonUseStartingDate { get; set; } 
    **[RequiredIfTrue("CommonUseStatus")]** 
    public DateTime CommonUseEndDate { get; set; } 
    public virtual FoundationCode FoundationCode { get; set; } 
} 

答えて

0

どのように私はこのように、この属性を使用できますか?バリデータは、属性装飾プロパティが必要とされているかどうかを判断するためにブールプロパティを参照することができる方法

public bool CommonUseStatus { get; set; } 

:あなたが参照しようとしているプロパティを追加することにより

+0

FoundatinCodeにはCommonUseStatusプロパティがあります。私は質問を追加するのを忘れました –

+0

@AliFuat:そのライブラリの内部の動作は私には分かっていないのでほとんどの推測ですが、属性に "FoundationCode.CommonUseStatus"を使用できますか? – David

+0

作業をしないFoundationCose.CommonUseStatus –

関連する問題