Home Display image from byte array in ASP.NET MVC Core
Reply: 0

Display image from byte array in ASP.NET MVC Core

user1503
1#
user1503 Published in April 26, 2018, 5:39 am

I have a byte[] stored in a VARBINARY(MAX) column in a table in my database. I want to show this image on my index.cshtml page - but I'm stuck.

My CSHTML looks like this:

@using Microsoft.AspNetCore.Hosting.Internal
@{
    ViewData["Title"] = "Title";
}
<h2>@ViewData["Title"]</h2>
<h3>@ViewData["Message"]</h3>
@if (!Context.User.Identity.IsAuthenticated)
{
    <p>blah blah.</p>

    <p>blah blah</p>
}

@if (Context.User.Identity.IsAuthenticated)
{
    <p>Hi @(Context.User.Identity.Name)<br/></p>


    <p>Where we off to today?</p>
}

I want to add

<img src="...." /> 

obviously I don't know what to do here.

My model has the byte array data:

 public byte[] UserImage { get; set; }

My controller assigned that the value:

  var model = new IndexViewModel
            {
                Username = user.UserName,
                Email = user.Email,
                PhoneNumber = user.PhoneNumber,
                IsEmailConfirmed = user.EmailConfirmed,
                StatusMessage = StatusMessage,
                UserImage = user.UserImage
            };

but I am using .net core in VS2017 and the answers I have found don't seem to work for me. Any help would be really appreciated.

Thanks Johan

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.260325 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO