This commit is contained in:
Michael 2017-03-25 16:56:05 -04:00
parent d5e460acf2
commit be641700f8
2 changed files with 8 additions and 4 deletions

View file

@ -43,12 +43,15 @@ namespace Project_Unite.Controllers
string[] allowedTypes = new[] { ".png", ".jpg", ".bmp", ".jpeg", ".gif" }; string[] allowedTypes = new[] { ".png", ".jpg", ".bmp", ".jpeg", ".gif" };
bool containsAllowedType = false; bool containsAllowedType = false;
foreach(var ending in allowedTypes) if (model.Image != null)
{ {
if (model.Image.FileName.EndsWith(ending)) foreach (var ending in allowedTypes)
{ {
containsAllowedType = true; if (model.Image.FileName.EndsWith(ending))
break; {
containsAllowedType = true;
break;
}
} }
} }
if (containsAllowedType == false) if (containsAllowedType == false)

View file

@ -23,6 +23,7 @@ namespace Project_Unite.Models
public class UploadImageViewModel public class UploadImageViewModel
{ {
[Required(ErrorMessage = "Please select an image to upload.")] [Required(ErrorMessage = "Please select an image to upload.")]
[DataType(DataType.Upload)]
public HttpPostedFileBase Image { get; set; } public HttpPostedFileBase Image { get; set; }
} }