2
After a lot of pain, be able to save the photo in the directory and not in the bank. However it does appear on my tablet there in my Solution Explorer, more when opening the photo by windows explore it appears.
Because of this the photo is not displayed when editing the record. How to proceed?
Code that saves the 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;" />
Nothing yet! Photo does not appear
– Luiz Felipe
@Luizfelipe Please enter the HTML when rendering. What is populated in
src
?– Leonel Sanches da Silva
I’ve already done it. it brings the full path of the image. and is a valid way!
– Luiz Felipe
@Luizfelipe You can update your question with what appears in HTML?
– Leonel Sanches da Silva
Ah, never mind. I’ll save the photos in the bank anyway!
– Luiz Felipe
I didn’t understand this line. Programming is this, it needs patience, determination and logic. Insist more, give more detail, edit the question with more richness of detail. I’m sorry, I’m happy to say, if you always give up in the face of the first difficulty, my friend, you won’t get far. I wish you success.
– pnet