0

我正在使用万无一失的验证。打电话时

[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; }
}
4

1 回答 1

0

我怎样才能以这种方式使用这个属性?

通过添加您尝试引用的属性:

public bool CommonUseStatus { get; set; }

这样,验证器可以引用布尔属性来确定是否需要装饰属性的属性。

于 2016-04-08T13:13:55.377 回答