dotnet/aspnetcore · error · Error
EqualTo validator requires a non-empty "other" parameter.
Error message
EqualTo validator requires a non-empty "other" parameter.
What it means
The EqualTo validator (used by Blazor's client-side validation for [EqualTo]/compare scenarios, e.g. password confirmation) requires a configuration parameter named 'other' naming the field to compare against. If the rule is registered without that parameter, the validator cannot locate its comparison target and throws immediately rather than silently passing. It runs before any value check so the configuration is validated up front.
Solutions
- Ensure the form field renders the data-val-equalTo-other attribute naming the comparison field (e.g. data-val-equalTo-other="*.ConfirmPassword").
- If registering the validator programmatically, pass { other: 'OtherFieldName' } in params.
- Check the C# model uses [Compare(nameof(ConfirmPassword))] so tag helpers emit the correct client attribute.
- Verify no HTML sanitizer/minifier is stripping data-* attributes.
Example fix
<!-- before --> <input name="Password" data-val="true" data-val-equalTo="Mismatch" /> <!-- after --> <input name="Password" data-val="true" data-val-equalTo="Passwords do not match" data-val-equalTo-other="*.ConfirmPassword" />
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the rule carries its 'other' param before the validator runs
function equalToConfigured(params: any): boolean {
return !!params && typeof params.other === 'string' && params.other.length > 0;
} Type guard
function hasOtherParam(p: unknown): p is { other: string } {
return !!p && typeof (p as any).other === 'string' && (p as any).other.length > 0;
} Prevention
- Use [Compare(nameof(Other))] on the model so tag helpers emit data-val-equalTo-other.
- Audit rendered inputs to confirm data-val-equalTo-other is present.
- Ensure HTML sanitizers do not strip data-* attributes.
- When registering validators manually, always pass required params.
When it happens
Trigger: Thrown at line 13 when params.other is falsy — i.e. the validator was invoked (e.g. via data-val-equalTo-other attribute or programmatic registration) with no 'other' value supplied.
Common situations: A [Compare] / [EqualTo] attribute on the C# model whose client-side data-val-equalTo-other attribute was stripped by tag helpers, a misnamed attribute, or a hand-built form missing the other-field reference; using the validator directly without passing params.
Related errors
- FileExtensions validator requires a non-empty "extensions"…
- length/minlength/maxlength validator requires at least one…
- Range validator requires at least one of "min" or "max"…
- regex validator requires a non-empty "pattern" parameter.
- assembly must be defined when using a descriptor.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/4a777e6f0dbdc78c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Web.JS/src/Validation/Validators/EqualTo.ts:13
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
import { ValidationContext, ValidationResult, Validator, pass, fail } from '../ValidationTypes';
// Validates that the value equals another field's value (for password confirmation, etc.).
// Resolves "*.PropertyName" to the model-prefixed field name using the current field's name.
// Finds the other field by [name] attribute within the same form.
// Throws if the mandatory `other` parameter is missing.
export const equalToValidator: Validator = (context: ValidationContext): ValidationResult => {
const { value, element, params } = context;
if (!params.other) {
throw new Error('EqualTo validator requires a non-empty "other" parameter.');
}
if (!value) {
return pass();
}
const otherFieldName = resolveOtherFieldName(element.name, params.other);
if (!otherFieldName) {
return pass();
}
const form = element.closest('form');
if (!form) {
return pass();
}
const otherElement = form.querySelector<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>(`[name="${CSS.escape(otherFieldName)}"]`);
View on GitHub (pinned to 3600ca084e)