I have a model like this:
[IsValidInput]
public class Input
{
//different properties
}
With a custom validation attribute like this:
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class IsValidInput : ValidationAttribute
{
public override bool IsValid(object value)
{
try
{
ExternalValidator.Validate(value);
}
catch (CustomException ex)
{
foreach(var errorText in ex.GetDescriptions())
{
this.ErrorMessage = this.ErrorMessage + errorText;
}
return false;
}
return true;
}
}
Now I have one ErrorMessage object that contains multiple errors. I want to somehow return multiple ErrorMessage objects, so that in my view I will have a list with multiple list-items, like this:
- Validation error 1
- Validation error 2
How can I return a list of ErrorMessages to archieve this?