title: Show images in table from database in Asp.net-mvc3
body: <p>I have a table containing user information with image field and storing image in binary data.</p>
  
  <p>I want to show this images on my view page in a table with user information.</p>
  
  <p>my code is..
  Controller</p>
  
  <pre><code>public ActionResult About()
          {
  var data = db.dbtable.ToList();
  return View(data);
  }
  </code></pre>
  
  <p>Get Image method // reg is object of dbtable</p>
  
  <pre><code>public FileContentResult GetImage(int id)
          {            
              reg = db.dbtable.FirstOrDefault(i =&gt; i.RegNo == id);            
              if (reg != null)
              {
                  return File(reg.Photo, "image/jpeg");
              }
              else
              {
                  return null;
              }
          }
  </code></pre>
  
  <p>on view page..</p>
  
  <pre><code>@model IEnumerable&lt;MvcMySchool.dbtable&gt;
  
  &lt;table width="50"&gt;
      &lt;tr&gt;
          &lt;th&gt; 
              Registration No.
          &lt;/th&gt;
          &lt;th&gt;
              First Name
          &lt;/th&gt;
          &lt;th&gt;
              Last Name
          &lt;/th&gt;
          &lt;th&gt;
              City
          &lt;/th&gt;
          &lt;th&gt;
              Photo
          &lt;/th&gt;
      &lt;/tr&gt;
      @foreach (var item in Model)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.RegNo)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.FirstName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.LastName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.City)
              &lt;/td&gt;
              &lt;td&gt;
              @*HttpContext.Current.Response.Write("&lt;img width="75" height="75" src=@(Url.Action("GetImage", "Home", new { id = item.RegNo })) /&gt;")*@
                  &lt;img width="75" height="75" src=@(Url.Action("GetImage", "Home", new { id = item.RegNo })) /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  
  <p>It only shows the image in the first row and nothing after that.</p>
  
  <p>Thanks..</p>