In my controller I am trying to get the photo image but it doesn't come across on the view. I feel like the problem is with the code in the controller. What am I missing?
Controller:
public async Task<ActionResult> GetPhoto(long photoId, CancellationToken cancellationToken) { try { var photoFile = await _photoService.GetPhotoByPhotoIdAsync(photoId, cancellationToken) .ConfigureAwait(false); var image = photoFile.Image; if (photoFile == null || photoFile.Id < 1) { return NotFound(); } Response.Headers.Add("content-disposition", "inline;filename=" + photoFile); return File(image, "png"); } catch { return NotFound(); } }
View:
<div class="col-md-4"><div class="profile-img"> @{ if (Model.PhotoId != null) { <img src="@Url.Action("GetPhoto", "Photo", new {photoId = Model.PhotoId})" class="user" style="width: 150px; height: 150px;" alt="profile pic"/> } else {<div class="user egghead"></div> } }</div></div>