What I am trying to achieve is through partial postback I am trying to retrieve the string image. This is because My page contain almost 100 images and the size of page is large and because of that I want to have partial post back to retrieve the image scr in mvc - 5. The funtion get called in controller but the image not loaded in the page. I am trying to retrieve like this in view

  @{
       var PhotoGallary = (List<DisasterManagementDataAccess.Model.utblCMSPhoto>)ViewData["PhotoGallery"];
   }    
    @foreach (var item in PhotoGallary)
    {
      <div>
        <a href="#">
          <img id="@item.PhotoID" class="width100 marginlt15 fllt padding2 PhotoGallaryThumbnail" src="@Url.Action("GetPhoto", "Home", new { item.PhotoID })" alt="@item.PhotoTitle" title="@item.PhotoTitle" />
        </a>
      </div>
    }

and in HomeController I have like this which will retrieve the Image in string format which is stored in Database(SQL R2 Management Studio)

   public ActionResult GetPhoto(long PhotoID)
    {
        string filedata = "";
        string mimetype = null;
        objCMSPhoto = new CMSPhoto();
        var model = objCMSPhoto.utblCMSPhotos.Where(x => x.PhotoID == PhotoID);
        foreach (var item in model)
        {
            if (item.NormalImage.Length > 0)
            {
                filedata = item.NormalImage;
            }
            break;
        }
        return  Content(filedata);
   }

I have taken reference from this question. I also tried to return string but the result was same. When I debug in filedata I get this kind of string:

   data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBXgFeAAD/4bWKRXhpZgAATU0AKgAAAAgADQEOAAIAAAAgAAAAqgEPAAIAAAAFAAAAygEQAAIAAAALAAAA0AESAAMAAAABAAEAAAEaAAUAAAABAAAA3AEbAAUAAAABAAAA5AEoAAMAAAABAAIAAAExAAIAAAARAAAA7AEyAAIAAAAUAAAA/gITAAMAAAABAAIAAIdpAAQAAAABAAABEogl............

What should I need to do?

Related posts

Recent Viewed