2
I created the following method to save an image in the database
public ActionResult enviaArquivo(UsurioViewModel arq)
{
try {
string nomeArquivo ="";
if (arq.Arquivo != null && arq.Arquivo.ContentLength > 0)
{
nomeArquivo= Path.GetFileName(arq.Arquivo.FileName);
var caminho = Path.Combine(Server.MapPath("~/images"), nomeArquivo);
arq.File.SaveAs(caminho);
arq.CaminhoArquivo = caminho;
}
ViewBag.Mensagem = "Arquivo: " + nomeArquivo+ ", enviado com sucesso.";
}
catch (Exception ex)
{
ViewBag.Mensagem("Erro:" + ex);
}
return View();
}
Now I need to create a method to recover the server image and display it in html, read some tutorials and watched some videos, but it’s still not clear to me how to do. If anyone can help me, I’d be very grateful!!! :)
Hello Ana, what exactly is not clear? As you said you want the image in html, just include your path in a tag
img
, once you have the path and name of the image when you uploaded it:<img src='/imagens/nomearquivo'/>
.– Ricardo Pontual