根据条件要求验证

时间:2012-10-24 06:12:24

标签: asp.net-mvc-3 validation unobtrusive-validation

     public string InsuredName
              {
                  get;
                  set;
              }
  public string Card_No
          {
              get { return this.card_No; }
              set { this.card_No = value; }
          }

这里我有两个专业,CardNo只需要一些InsuredNames。当用户输入InsuredName然后我想去数据库并检查它是否有Card_No验证如果是,那么我想要根据需要验证它不是,我尝试远程验证,但它无法正常工作

1 个答案:

答案 0 :(得分:0)

private string insuredName;
  private bool cardNoRequiresValidation;
  public string InsuredName
              {
                  get {return insuredName;}
                  set { cardNoRequiresValidation = DoesCardNoRequiresValidation(Value); insuredName = value;}
              }
  public string Card_No
          {
              get { return this.card_No; }
              set { cardNoRequiresValidation ? ValidateCardNo(value) : card_No =  value; }
          }
  private bool DoesCardNoRequiresValidation(string insuredName)
  { //if requires validation 
    // return true;
    //else 
    //return false;
  }
  private void ValidateCardNo(string cardNo)
  {
    //execute validation logic
  }