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,6 +43,8 @@ namespace Project_Unite.Controllers
string[] allowedTypes = new[] { ".png", ".jpg", ".bmp", ".jpeg", ".gif" };
bool containsAllowedType = false;
if (model.Image != null)
{
foreach (var ending in allowedTypes)
{
if (model.Image.FileName.EndsWith(ending))
@ -51,6 +53,7 @@ namespace Project_Unite.Controllers
break;
}
}
}
if (containsAllowedType == false)
ModelState.AddModelError("UploadImageViewModel", new Exception("File type not allowed."));

View file

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