I'm Ali I need some help. I need to display an image in a view.
I can to store the image in the database by converting it to an array and storign it. But now I can't display the image in my view.
How do that?
I would like to support you with an example.
My model class:
One of the cleanest way to do this is to create a new HtmlExtension class which will convert bytes to base64 string and then returns the mvc html string
public static class HtmlExtensions
{
public static MvcHtmlString Image(this HtmlHelper html, byte[] image)
{
var img = String.Format("data:image/jpg;base64,{0}", Convert.ToBase64String(image));
return new MvcHtmlString("<img src='" + img + "' />");
}
}
Then you can use that in any view
@Html.Image(Model.Imag)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.