Im displaying an image on my page like so
<img src="data:image;base64,@System.Convert.ToBase64String(Model.PhotoDisplay)" />
my model
public byte[] PhotoDisplay { get; set; }
However PhotoDisplay may not have an image so may returns null so im getting an error
An exception of type 'System.ArgumentNullException' occurred in mscorlib.dll but was not handled in user code
Additional information: Value cannot be null."
How what the best way to handle this, example would be great.
@if(Model.PhotoDisplay != null) { <img src="data:image.....PhotoDisplayisnullPhotoDisplayhas any value. If not, just return the transparent pixel (i.e it's base64 value).Model.PhotoDisplay = Model.PhptoDisplay ?? System.IO.File.ReadAllBytes(emptyImagePath)may be?