title: displaying image from db in Razor/MVC3
body: <p>I have a table in the db, which has the following :- CountryID, CountryName, and CountryImage.</p>
  
  <p>Now I am trying to display the image in the index and I have the following in the View :-</p>
  
  <pre><code>        &lt;td&gt;
          @if (item.Image != null)
          {
              &lt;img src="@Model.GetImage(item.Image)" alt="@item.CountryName"/&gt;    
          }
  </code></pre>
  
  <p>and then in the ViewModel I have :-</p>
  
  <pre><code>        public FileContentResult GetImage(byte[] image)
      {
          if (image != null)
              return new FileContentResult(image, "image/jpeg");
          else
          {
              return null;
          }
      }
  </code></pre>
  
  <p>However I cannot see the image properly.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks in advance for your help and time</p>
  
  <p>UPDATE</p>
  
  <p>Ok So I have implemented the following in the View :-</p>
  
  <pre><code>        &lt;td&gt;
          @if (item.Image != null)
          {
              &lt;img src="@Url.Action("GetImage", "CountryController", new { id = item.CountryID })" alt="@item.CountryName" /&gt;             
          }
      &lt;/td&gt;
  </code></pre>
  
  <p>and in the CountryController :-</p>
  
  <pre><code>        public ActionResult GetImage(int id)
      {
          var firstOrDefault = db.Countries.Where(c =&gt; c.CountryID == id).FirstOrDefault();
          if (firstOrDefault != null)
          {
              byte[] image = firstOrDefault.Image;
              return File(image, "image/jpg");
          }
          else
          {
              return null;
          }
      }
  </code></pre>
  
  <p>but when I try to debug the code, the ActionResult GetImage is not being hit</p>