good day ... I need a help .. I can not show an image that I have in my database .. even add it to the directory .. creates the image but does not show it .. in the directory the solution does not appear .. I only see it when I access from the folders I am using asp.net Mvc 5 visual 2017 the community version
// en el controlador mi metodo al crear la imagen por metodo post
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "PacienteID,NombrePaciente,Apellidos,Ci,FechaNac,Telefono,Direccion,Email")] Paciente paciente, HttpPostedFileBase imagenPaciente)
{
if (imagenPaciente != null && imagenPaciente.ContentLength > 0)
{
byte[] imagenData = null;
string path = Path.Combine(Server.MapPath("~/Content/Images/"),
Path.GetFileName(imagenPaciente.FileName));
//crea el directorio
imagenPaciente.SaveAs(path);
// guardo la ruta en la entidad paciente
paciente.FotoUrl = path;
ViewBag.ImageData = path;
using (var binaryPaciente = new BinaryReader(imagenPaciente.InputStream))
{
imagenData = binaryPaciente.ReadBytes(imagenPaciente.ContentLength);
}
/creo la foto en la direccion y guardo los byte en mi bd ..
paciente.Foto = imagenData;
}
if (ModelState.IsValid)
{
db.Paciente.Add(paciente);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(paciente);
}
this is my view
@model IEnumerable<PruebaImagenes.Models.Paciente>
@{
ViewBag.Title = "Index";
@ViewBag.conversion;
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.NombrePaciente)
</th>
<th>
@Html.DisplayNameFor(model => model.Apellidos)
</th>
<th>
@Html.DisplayNameFor(model => model.Ci)
</th>
<th>
@Html.DisplayNameFor(model => model.FechaNac)
</th>
<th>
@Html.DisplayNameFor(model => model.Foto)
</th>
<th>
@Html.DisplayNameFor(model => model.Telefono)
</th>
<th>
@Html.DisplayNameFor(model => model.Direccion)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.NombrePaciente)
</td>
<td>
@Html.DisplayFor(modelItem => item.Apellidos)
</td>
<td>
@Html.DisplayFor(modelItem => item.Ci)
</td>
<td>
@Html.DisplayFor(modelItem => item.FechaNac)
</td>
<td>
@if (item.FotoUrl != "")
{
// esta parte no me agarra la imagen..
<img src="@item.FotoUrl" width="50" height="50" /> // muestra el mensaje del tag <p>
<p>imagen dentro del src</p>
}
@Html.DisplayFor(modelItem => item.FotoUrl)
</td>
<td>
@Html.DisplayFor(modelItem => item.Telefono)
</td>
<td>
@Html.DisplayFor(modelItem => item.Direccion)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.PacienteID }) |
@Html.ActionLink("Details", "Details", new { id = item.PacienteID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.PacienteID })
</td>
</tr>
}
</table>
the model is this
public class Paciente
{
[Key]
public int PacienteID { set; get; }
[Required(ErrorMessage = "nombre Obligatorio")]
[Display(Name = "Nombre del Paciente")]
public string NombrePaciente { set; get; }
[Required(ErrorMessage = "apellido Obligatorio")]
[Display(Name = "Apellido del paciente")]
public string Apellidos { set; get; }
[Required]
[Display(Name = "Numero de Carnet de Identidad")]
public string Ci { get; set; }
[Required(ErrorMessage = "fecha de nacimiento obligatoria")]
[Display(Name = "Fecha de Nacimiento")]
public DateTime FechaNac { set; get; }
public byte[] Foto { set; get; }
[Required]
[DataType(DataType.PhoneNumber)]
[Display(Name = "Numero de telefono")]
public string Telefono { set; get; }
[Required]
[Display(Name = "Direccion domicilio")]
public string Direccion { set; get; }
[DataType(DataType.EmailAddress)]
[Display(Name = "Correo electronico")]
public string Email { set; get; }
public string FotoUrl { set; get; }