kez
kez

Reputation: 2313

How to display a byte array image from model when its null?

I want to leave as null or show as an image if that byte array image existing in DB column.

Currently I'm showing its like this

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

but when this Model.ProfilePicture null I'm getting error like following

Value cannot be null. Parameter name: inArray

Upvotes: 0

Views: 613

Answers (1)

user3559349
user3559349

Reputation:

Wrap the <img> tag in a if block that check if the property has a value

@if (Model.ProfilePicture != null)
{
    <img src="data:image;base64,@System.Convert.ToBase64String(Model.ProfilePicture)" width="80" height="80" />
}

Upvotes: 1

Related Questions