At the moment I have a custom validation attribute called ExistingFileName (below) but i have given it error messages to display
protected override System.ComponentModel.DataAnnotations.ValidationResult IsValid(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext)
{
if (value!=null)
{
string fileName = value.ToString();
if (FileExists(fileName))
{
return new ValidationResult("Sorry but there is already an image with this name please rename your image");
}
else
{
return ValidationResult.Success;
}
}
else
{
return new ValidationResult("Please enter a name for your image");
}
}
I have implemented it like so:
[ExistingFileName]
public string NameOfImage { get; set; }
Im sure theres a way to define the error message when setting the attribute like below:
[ExistingFileName(errormessage="Blah blah blah")]
public string NameOfImage { get; set; }
But I'm not sure how? Any help is greatly appreciated