私はビューモデルを持っています
[CustomValidation(typeof(MyValidation), "MyMethod")]
[Serializable()]
public class TransactionViewModel
{
public string InvoiceNumber;
}
public class MyValidation
{
public static ValidationResult validatelength(TransactionViewModel length)
{
bool isValid;
if (length.InvoiceNumber.Length >15)
isValid = false;
else
isValid = true;
if (isValid)
{
return ValidationResult.Success;
}
else
{
return new ValidationResult(
"The Field value is greater than 15");
}
}
}
検証が失敗した場合、クラスオブジェクトのいくつかのフィールドをチェックしていますコントローラーでモデルの状態をチェックし、請求書番号のビュー、追加された検証メッセージを返しますが、まだエラーが発生しません
検証属性をモデル ビューに適用できますか。私が何か間違ったことをしている場合、PLS は解決策を提供します。