0

http://msdn.microsoft.com/en-us/library/f5db6z8k(v=vs.100).aspxから

入力されたデータが Db に存在するかどうかを確認する customeValidators.cs ページを作成しました。これは機能します。ただし、必要なページからこれを呼び出そうとすると

protected void runUniqueReference(object source, ServerValidateEventArgs args)
{
    args.IsValid = (CustomValidators.UniqueReference(BOQRefTextBox.Text));
}

でエラーが発生しましたCustomValidators.UniqueReference。「データ注釈」を「ブール」に変換できません。何か考えはありますか? 編集;

 public static ValidationResult UniqueReference(string Reference)
    {
        ContextDB db = new  ContextDB();

        var lisStoredInDB =
            (from Bill in db.Bill_Of_Quantities
             where Bill.Reference == Reference
             select Bill.Reference).ToList();

        if (lisStoredInDB.Count != 0)
        {
            return new ValidationResult(string.Format("This reference is already stored in the database, Please enter another"));
        }

        return ValidationResult.Success;
    }
4

1 に答える 1

1

args.IsValidは typeboolでありCustomValidators.UniqueReference、その型の値を返してはなりません。したがって、

args.IsValid = (CustomValidators.UniqueReference(BOQRefTextBox.Text));

UniqueReferenceの戻り値をに代入できないため、機能しませんIsValid

UniqueReferenceを返すのでValidationResult、おそらく次のようになります。

args.IsValid = (CustomValidators.UniqueReference(BOQRefTextBox.Text)).IsValid;
于 2013-01-25T12:51:07.723 に答える