Hello,
I created a custom validator to validate the Mime type of an HttpPostedFileBase:
public class FileMimeTypeValidator : PropertyValidator {
private List<String> _types;
public FileMimeTypeValidator(List<String> types)
: base(() => Resources.Message.FileMimeType) {
if (types == null) throw new ArgumentNullException("types");
_types = types;
} // FileMimeTypeValidator
protected override Boolean IsValid(PropertyValidatorContext context) {
HttpPostedFileBase file = (HttpPostedFileBase)context.PropertyValue;
return file == null ? true : file.ContentLength == 0 ? true : _types.Contains(file.ContentType);
} // Validate
} // FileMimeTypeValidator
I have a model with a property of type HttpPostedFileBase[].
How can I apply my validator only to the first item of this array?
Is this possible?
Thank You,
Miguel