title: How to display binary images from Database to edit form using MVC 4
body: <p>I am storing images in Database as Binary Images successfully.
  I want to display these images in Edit form to modify and save changes.
  System.OutOfMemoryException' was thrown in Edit.cshtml form while displaying Binary Images from Database.</p>
  
  <p>Can someone please correct my code.</p>
  
  <p>Model class:</p>
  
  <pre><code>public class Accommodation
      {
          [Key]
          public string A_Unique_Id { get; set; }
  
          public byte[] Picture1 { get; set; }
  
          public byte[] Picture2 { get; set; }
  
          public byte[] Picture3 { get; set; }
  
  
    }
  </code></pre>
  
  <p>// GET: /Accommodation/Edit/5  </p>
  
  <pre><code>public ActionResult Edit(string id)
      {
          Accommodation accommodation = db.Accommodation.Find(id);
          ViewBag.SelectedAustraliaStateId = new SelectList(db.AustraliaStates, "AustraliaStateId", "AustraliaStateName", accommodation.SelectedAustraliaStateId);
  
          return View(accommodation);
      }
  </code></pre>
  
  <p>// POST: /Accommodation/Edit/5</p>
  
  <pre><code>[HttpPost]
  public ActionResult Edit(Accommodation accommodation)
  {
      if (ModelState.IsValid)
      {
          db.Entry(accommodation).State = EntityState.Modified;
  
          //the following line is for re-assigning back the DDL modified value.
          accommodation.State = accommodation.SelectedAustraliaStateId;
  
          db.SaveChanges();
          return RedirectToAction("Index");
      }
      return View(accommodation);
  }
  </code></pre>
  
  <p>Edit.cshtml</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Picture1)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Picture1)
          @Html.ValidationMessageFor(model =&gt; model.Picture1)
      &lt;/div&gt;
  </code></pre>
  
  <p><strong>ERROR MESSAGE:</strong> Exception of type 'System.OutOfMemoryException' was thrown at line <code>@Html.EditorFor(model =&gt; model.Picture1)</code></p>