I need to upload a csv file and I want to restrict it's extension to .csv
So I added the follow property to my ViewModel:
[FileExtensions(ErrorMessage = "Must choose .csv file.",Extensions = "csv,txt")]
public HttpPostedFileBase File { get; set; }
In my view I have the following:
@Html.TextBoxFor(m => m.File, new { type = "file"})
@Html.ValidationMessageFor(m => m.File)
However as soon as it hits my "ModelState.IsValid" check it returns invalid with my error message of "Must choose .csv file."
I assume I'm just missing a parameter, but I haven't found a sample of this in use any where yet.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…