I am trying to implement a file downloader that can accept different numbers of files. Input elements for file input have the same name, so create a list of files that MVC3 happily associates with.
So in my controller I have
public virtual ViewResult UploadReceive(IEnumerable<HttpPostedFileBase> Files ){
This gets all the files it needs. However, all empty form file input elements add zero. This stops my basic non-empty list check in the controller from working as I want.
Verification is performed below:
public class EnsureMinimumElementsAttribute : ValidationAttribute { private readonly int _minElements; public EnsureMinimumElementsAttribute(int minElements) { _minElements = minElements; } public override bool IsValid(object value) { var list = value as IList; if (list != null) { return list.Count >= _minElements; } return false; } }
Any idea how I can change the validation to generally only count non-zero elements?
source share