Open Closed

Getting Validation Result Twice #1158


User avatar
0
learnabp created
  • ABP Framework version: v4.2.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:

I am trying to have a validate confirm password input with password input, please see below code

I am getting the Validation Error come up twice please see below screen shot.

can you please suggest why i am getting the error twice?

public virtual async Task<IActionResult> OnPostAsync()
        {
            ValidateModel();

            var input = ObjectMapper.Map<TenantInfoModel, SaasTenantCreateDto>(Tenant);
            await TenantRegistrationAppService.RegisterTenantAsync( new RegisterTenantInputDto { SaasTenantCreateDto = input });

            return NoContent();
        }

        public class TenantInfoModel : ExtensibleObject, IValidatableObject
        {
            [Required]
            [StringLength(TenantConsts.MaxNameLength)]
            public string Name { get; set; }

            [SelectItems(nameof(EditionsComboboxItems))]
            public Guid? EditionId { get; set; }

            [Required]
            [EmailAddress]
            [StringLength(256)]
            public string AdminEmailAddress { get; set; }

            [Required]
            [DataType(DataType.Password)]
            [StringLength(128)]
            [DisableAuditing]
            public string AdminPassword { get; set; }

            [Required]
            [DataType(DataType.Password)]
            [StringLength(128)]
            [DisableAuditing]
            public string ConfirmAdminPassword { get; set; }

            public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
            {
                if (!AdminPassword.Equals(ConfirmAdminPassword , StringComparison.Ordinal))
                {
                    yield return new ValidationResult(
                        "The passwords do not match!",
                        new[] { "AdminPassword", "ConfirmAdminPassword" }
                    );
                }

                base.Validate(validationContext);
            }
        }

4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try to remove base.Validate(validationContext);

  • User Avatar
    0
    learnabp created

    no thats not it still same result

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to specify one member?

    yield return new ValidationResult(
        "The passwords do not match!",
        new[] { "ConfirmAdminPassword" }
    );
    
  • User Avatar
    0
    learnabp created

    Yes that works

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on July 11, 2025, 11:35