2025-03-24 16:53:32 +08:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-12-27 21:50:13 +08:00
|
|
|
|
|
|
|
|
|
|
namespace LMS.Common.Attributes
|
|
|
|
|
|
{
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Property)]
|
|
|
|
|
|
public class NotEmptyAttribute : ValidationAttribute
|
|
|
|
|
|
{
|
|
|
|
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value is string str && string.IsNullOrWhiteSpace(str))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ValidationResult(ErrorMessage ?? "字段不能为空");
|
|
|
|
|
|
}
|
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|