Skip to content

Commit fad547d

Browse files
committed
refactor: 兼容非 Attribute 结尾的验证规则
1 parent 248165c commit fad547d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ private void ValidateDataAnnotations(object? value, ValidationContext context, L
419419
// 查找 resource 资源文件中的 ErrorMessage
420420
var ruleNameSpan = rule.GetType().Name.AsSpan();
421421
var index = ruleNameSpan.IndexOf(attributeSpan, StringComparison.OrdinalIgnoreCase);
422-
var ruleName = ruleNameSpan[..index];
422+
var ruleName = index == -1 ? ruleNameSpan[..] : ruleNameSpan[..index];
423423
if (LocalizerFactory.Create(context.ObjectType).TryGetLocalizerString($"{memberName}.{ruleName.ToString()}", out msg))
424424
{
425425
rule.ErrorMessage = msg;

0 commit comments

Comments
 (0)