Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to get a photo image to show via Controller

$
0
0

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>


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>