0

I am using Foolproof Validation . When calling

[RequiredIfTrue("CommonUseStatus")]

Foolproof ReqiuredIfAttribute gives System.NullReferenceException. Because CommonUseInfo haven't got CommonUseStatus property. How can I use this Attribute in this way?

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; }
}
Ali Fuat
  • 9
  • 2

1 Answers1

0

How can I use this Attribute in this way?

By adding the property you're attempting to reference:

public bool CommonUseStatus { get; set; }

That way the validator can reference the boolean property to determine whether or not the attribute-decorated property is required.

David
  • 208,112
  • 36
  • 198
  • 279
  • FoundatinCode has a CommonUseStatus property. I forgot to add question – Ali Fuat Apr 09 '16 at 07:11
  • @AliFuat: Mostly a guess since the inner workings of that library are unknown to me, but can you use "FoundationCode.CommonUseStatus" in the attribute? – David Apr 09 '16 at 12:02