Problem displaying image

0

As I display an image recorded in the database, I believe it is not actually recorded, because I can only see the name / format of the image. In this case, how do I display this image?

I looked for some ways to do it using custom HTML helpers and etc., but I think I'm forgetting something.

Here is my image upload code:

[HttpPost]
public ActionResult Adicionar(usuario usuario, HttpPostedFileBase foto)
{
    if (ModelState.IsValid)
    {
        db.usuario.Add(usuario);
        db.SaveChanges();
        var fotoperfil = Path.GetFileName(foto.FileName);
        var caminho = Path.Combine(Server.MapPath("~/App_Data/Foto"), fotoperfil);
        foto.SaveAs(caminho);
        return RedirectToAction("Index");
    }
    return View(usuario);               
}
    
asked by anonymous 14.09.2014 / 03:42

1 answer

1

You need to save the change in Model , as below:

[HttpPost]
public ActionResult Adicionar(usuario usuario, HttpPostedFileBase foto)
{
    if (ModelState.IsValid)
    {
        db.usuario.Add(usuario);
        db.SaveChanges();
        var fotoperfil = Path.GetFileName(foto.FileName);
        var caminho = Path.Combine(Server.MapPath("~/App_Data/Foto"), fotoperfil);
        foto.SaveAs(caminho);

        usuario.ArquivoDaFoto = caminho;
        return RedirectToAction("Index");
    }
    return View(usuario);               
}

ArquivoDaFoto must be String .

    
14.09.2014 / 04:19