Table of Contents

Class RequiredValidator

Namespace
BootstrapBlazor.Components
Assembly
BootstrapBlazor.dll

Required 验证实现类

public class RequiredValidator : ValidatorBase, IValidator
Inheritance
RequiredValidator
Implements
Derived
Inherited Members
Extension Methods

Constructors

RequiredValidator()

public RequiredValidator()

Properties

AllowEmptyString

获得/设置 是否允许空字符串 默认 false 不允许

public bool AllowEmptyString { get; set; }

Property Value

bool

ErrorMessage

获得/设置 错误描述信息 默认为 null 需要赋值

public string? ErrorMessage { get; set; }

Property Value

string

LocalizerFactory

获得/设置 IStringLocalizerFactory 注入服务实例 默认为 null

public IStringLocalizerFactory? LocalizerFactory { get; set; }

Property Value

IStringLocalizerFactory

Options

获得/设置 Json 资源文件配置 默认为 null

public JsonLocalizationOptions? Options { get; set; }

Property Value

JsonLocalizationOptions

Methods

GetLocalizerErrorMessage(ValidationContext, IStringLocalizerFactory?, JsonLocalizationOptions?)

通过资源文件获取 ErrorMessage 方法

protected virtual string? GetLocalizerErrorMessage(ValidationContext context, IStringLocalizerFactory? localizerFactory = null, JsonLocalizationOptions? options = null)

Parameters

context ValidationContext
localizerFactory IStringLocalizerFactory
options JsonLocalizationOptions

Returns

string

GetRuleKey()

获得当前验证规则资源文件中 Key 格式

protected virtual string GetRuleKey()

Returns

string

Validate(object?, ValidationContext, List<ValidationResult>)

验证方法

public override void Validate(object? propertyValue, ValidationContext context, List<ValidationResult> results)

Parameters

propertyValue object

待校验值

context ValidationContext

ValidateContext 实例

results List<ValidationResult>

ValidateResult 集合实例