This is my database in SQL Server, I saved the image in an image
column:
CREATE TABLE registro
(
id int IDENTITY(1, 1),
Nombre varchar(100),
appaterno varchar(100),
apmaterno varchar(100),
lineainvestigacion varchar(100),
correo varchar(100),
correoi varchar(100),
telefonop int,
extension int,
telefonoof int,
usuario varchar(100) PRIMARY KEY ,
clave varchar(100),
imagen image,
idrol varchar(100),
ciudadr varchar(100)
);
Where looking at the data through a select
, it shows that I have my image saved:
This is my class:
public class Registro1
{
public int id { get; set; }
public string nombre { get; set; }
public string appaterno { get; set; }
public string apmaterno { get; set; }
public string correo { get; set; }
public string usuario { get; set; }
public string clave { get; set; }
public string Imagen { get; set; }
public string image
{
get { return Imagen.Replace(" ", string.Empty) + ".jpg"; }
}
public string idrol { get; set; }
public string lineainvestigacion { get; set; }
public string correoi { get; set; }
public int telefonoof { get; set; }
public double telefonop { get; set; }
public int extension { get; set; }
public string ciudadr { get; set; }
}
And this is my controller:
public ActionResult VistaPerfil(Registro1 rg)
{
connectionString();
con.Open();
com.Connection = con;
com.CommandText =
"select Nombre,lineainvestigacion,correo,correoi,telefonop,extension,telefonoof,ciudadr,clave,imagen
from registro where usuario='" + rg.usuario + "'";
SqlDataReader dr;
try
{
dr = com.ExecuteReader();
while (dr.Read() == true)
{
rg.nombre = dr["Nombre"].ToString();
rg.lineainvestigacion = dr["lineainvestigacion"].ToString();
rg.correo = dr["correo"].ToString();
rg.correoi = dr["correoi"].ToString();
rg.telefonop = Convert.ToInt32(dr["telefonop"]);
rg.extension = Convert.ToInt32(dr["extension"]);
rg.telefonoof = Convert.ToInt32(dr["telefonoof"]);
rg.ciudadr = dr["ciudadr"].ToString();
rg.clave = dr["clave"].ToString();
rg.Imagen= dr["imagen"].ToString();
ViewData["Nombre"] = rg.nombre;
ViewData["lineainvestigacion"] = rg.lineainvestigacion;
ViewData["correo"] = rg.correo;//correo personal
ViewData["correoi"] = rg.correoi;//correo institucional
ViewData["telefonop"] = rg.telefonop;
ViewData["extension"] = rg.extension;
ViewData["telefonoof"] = rg.telefonoof;
ViewData["ciudadr"] = rg.ciudadr;
ViewData["clave"] = rg.clave;
ViewData["imagen"] =rg.Imagen;
con.Close();
return View("../Home/Perfil");
}
}
catch (Exception es)
{
con.Close();
Response.Write("<script>alert('Perfil no visto =(')</script>");
return View("../Home/Perfil");
throw es;
}
}
Through this function I try to load the image so that it is shown in my view:
<form action="VistaPerfil" method="post">
<div class="row">
<div class="col-md-6">
<label>Imagen:</label>
</div>
<div class="col-md-6">
<p>
@ViewData["imagen"]
</p>
</div>
</div>
<button type="submit" class="btn btn-primary btn-block"> Ver datos</button>
</form>
The error I get is that it does not show me the image as shown in the screenshot:
I would like to know how to convert from string to some attribute to show the image or some other solution.