I have a custom registration form in which I save a photo of who is registering:
The image is saved as a byte array in the sql database. In the Home controller I have created the following method:
public FileContentResult getImage()
{
var owin = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = owin.FindByEmail<ApplicationUser, string>(User.Identity.Name);
byte[] biteIMG = result.Logo;
MemoryStream m = new MemoryStream(biteIMG);
Image image = Image.FromStream(m);
m = new MemoryStream();
image.Save(m, ImageFormat.Png);
m.Position = 0;
return new FileContentResult(biteIMG, "image/png");
}
And when I go to the following path https://localhost:44397/Home/getImage , the image looks fine:
However, what I want is for the image to appear in a div or in an html image but in the Home html or simply show it anywhere or in any other controller. I have tried the following but it doesn't work:
I also tried the following and it doesn't work:
<img src="https://localhost:44397/Home/getImage" alt="avatar" />
Does anyone know how to do this to be able to put it in one div
or image
in html5?
In order to display your image in a control of type
<img />
, you must use the HtlmHelper@Url.Action()
.From the View you want to display the image in, you need to call the
getImage
Controller ActionHome
on the attributesrc=
of your<img />
.The code would be the following: