Home > Software design >  Image is not being displayed from varbinary
Image is not being displayed from varbinary

Time:10-04

I have a SQL Server database and in one of the columns in my table is of type varbinary(max) and has a value like this:

0x3131313131313031313131313130313...

I couldn't enter the whole value because stackoverflow won't allow it.

I am fetching this data using api in my controller.

I am trying to display this image in ASP.NET MVC using the following markup in my .cshtml file:

<img alt="image" src="data:image/jpg;base64, @Convert.ToBase64String(item.FlImage)" height="200" width="200" />

but the image is not being displayed when I run it.

Can anyone help and explain what's going wrong?

CodePudding user response:

<img alt="image" src="data:image/jpg;base64, @Convert.ToBase64String(item.FlImage)" height="200" width="200" />

this is the correct code. just make sure the extension of your image file and here in img tag match. plus my error was that my binary code was wrong in database. i fixed it and now its working.

  • Related