List<String> _lista = new List<String>();
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Veiculo veiculo, HttpPostedFileBase[] file)
{
for (int i = 0; i < file.Length; i++)
{
var fileName = Guid.NewGuid().ToString() +
System.IO.Path.GetExtension(file[i].FileName);
file[i].SaveAs(HttpContext.Server.MapPath("~/Fotos/")
+ fileName);
_lista.Add(fileName);
}
veiculo.Imagem1 = _lista[0];
veiculo.Imagem2 = _lista[1];
veiculo.Imagem3 = _lista[2];
veiculo.Imagem4 = _lista[3];
veiculo.Imagem5 = _lista[4];
db.Veiculo.Add(veiculo);
db.SaveChanges();
return RedirectToAction("Index");
}
What I need is for the user to be able to upload as many images as he wants, not just 5 as he is done in my code.