0

I've seen an answer to this in MVC3 "Displaying database image (bytes[]) in Razor/MVC3", but it end using two trips.

Is there an improved way in MVC4/5 using razor? Will WebImage help. I'm learning but a lot of this is over my head

The previous questioner made this observation, I echo it.

" I've yet to see an example of the image being taken from the model/viewmodel and displayed (except my answer using TempData). You'd think it would be a common requirement, but either it's so simple no-one asks or it's so difficult no-one bothers."

My images are small bargraphs.

So in my view the collection is passed in the Model.Lots

@foreach (var item in Model.Lots) 
{ <tr>
<td> 
@item.LotName
</td>
<td>
// code here to take @item.TaskImage (a byte array) and show image
</td>
user2887440
  • 51
  • 1
  • 8

2 Answers2

0

As an example to get things working:

<img src="data:image/png;base64,@Convert.ToBase64String(item.TaskImage)" />

This technique uses the data URI scheme. We take the incoming byte array, convert it to Base64 and put it as the data in the URI.

Community
  • 1
  • 1
Rowan Freeman
  • 15,724
  • 11
  • 69
  • 100
0

see "Image to Byte[] harder than thought 2 challenges" for working answer.

user2887440
  • 51
  • 1
  • 8