After much pain, you can save the photo in the directory and not the bank. But she does not appear in my folder in my Solution Explorer, but when I open the photo through the windows explore it appears.
Because of this, the photo is not displayed when editing the record. How should I proceed?
Code that saves Photo:
int n = 0;
Boolean valido = true;
foreach (var item in ModelState.Values)
{
n++;
if ((item.Value == null) && (n < 12))
{
valido = false;
}
}
if (valido == true)
{
var file = Request.Files[0];
var fileName = Path.GetFileName(file.FileName);
var pat = Path.Combine(Server.MapPath("~/Fotos/"), fileName);
file.SaveAs(pat);
frota.URLFoto = fileName;
db.Frotas.Add(frota);
db.SaveChanges();
return RedirectToAction("Index");
}
Razor HTML:
@{ var foto = Model.URLFoto;
var pat = Path.Combine("~/Fotos/", foto); }
<img src="@pat" width="172" height="92" style="border: 1px solid black; width: 172px; height: 92px;" />