Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

ICustomValidate #8862


User avatar
0
james.marley created

I have some custom validation that I am trying to add to a CreateOrEditDto. As per the documentation I have implmented the ICustomValidate interface. I did a simple test where I add a Validation Result to the context results where I do a very basic check.

The validation result is added and I am presented with a message box that contains my error message and it does not submit the form which is fine.

I have two questions:

  1. In the form there is no translation for the error title or error narration. How do I go about adding this?
  2. There is an argument that can be passed to the ValidationResults constructor that takes a string IEnumerable of member names. What is the purpose of passing in this list of property names? I had assumed it would update the form showing the validation errors with the invalid form inputs but it doesn't do this.

I couldn't find anything specific in the documentation regarding the above two questions. Any advice on how this should work would be appreciated.

The code I have is below and a screen grab of the message box attached:

public void AddValidationErrors(CustomValidationContext context)
{
    if(Name == "Test")
    {
        context.Results.Add(new ValidationResult("This is a test", new [] { "Name" }));
    }
}


3 Answer(s)