Convert Byte Array to image and display in Razor View

Like this:

<img src="@Url.Action("getImg", "Person", new { id = item.Id })" alt="Person Image" />

You need Url.Action and not Html.Action because you just want to generate an url to the GetImg action. Html.Action does something entirely different.


There's an even easier way of doing this if you already happen to have the image loaded in your model:

<img src="data:image;base64,@System.Convert.ToBase64String(Model.Image)" />

Doing this way you do not need to go to the server again just to fetch the image byte[] from the database as you're doing.