title: How to display Images using HtmlHelper Class- ASP.NET MVC
body: <p>I am currently stuck with this problem of displaying an image using HtmlHelper class.</p>
  
  <p>Here is what i have.</p>
  
  <p>I have a custom HtmlHelper class which supposed to display an image:</p>
  
  <pre><code>public static string Images(this HtmlHelper helper, ......){
  
      var writer = new HtmlTextWriter(new StringWriter());
      byte[] bytearray = ... // some image byte array retrieved from an object.
  
      // begin html image tag - this is where the problem is
      writer.AddAttribute(HtmlTextWriterAttribute.Src, url.Action("GetPhoto", "Clinical", new { image = bytearray })); 
      writer.RenderBeginTag(HtmlTextWriterTag.Img); 
      writer.RenderEndTag();
      // end of image tag
  
      return writer.InnerWriter.ToString();
  }
  </code></pre>
  
  <p>So what i tried to do above is to inject a Url.Action into the img source attribute.</p>
  
  <p>I have a controller "GetPhoto" that is suppsoed to handle that bytearray and return an image.</p>
  
  <pre><code>public FileContentResult GetPhoto(byte[] image)
          {
  
              return File(image, "image/jpeg");
          }
  </code></pre>
  
  <p>I managed to get to the controller, but image shows as null. Is there a way around it ? or maybe an even better way to do this? Your help will be very much appreciated, Thanks!</p>