title: How to upload/display images using ASP.net MVC4 with Entity Framework
body: <p>I have a data model like so </p>
  
  <pre><code>    public class NewsItem
  {
      public virtual int Id { get; set; }
      public virtual string NewsTitle { get; set; }
      public virtual string NewsContent { get; set; }
      public virtual byte[] NewsImage { get; set; }
      public virtual DateTime DateAdded { get; set; }
      public virtual bool IsLive { get; set; }
  }
  </code></pre>
  
  <p>I then display this data through a View like so:</p>
  
  <pre><code>@model BusinessObject.Domain.NewsItem
  &lt;div class="row-fluid"&gt;
      &lt;h3&gt;
          @Html.ValueFor(model =&gt; model.NewsTitle)
      &lt;/h3&gt;
      &lt;div class="span5"&gt;
      &lt;img src="~/Content/images/stock.jpg" /&gt;
      &lt;/div&gt;
  
  &lt;div class="span7"&gt;
  &lt;p&gt;
      @Html.ValueFor(model =&gt; model.DateAdded)
  &lt;/p&gt;
  &lt;p&gt;
      @Html.ValueFor(model =&gt; model.NewsContent)
  &lt;/p&gt;
  &lt;/div&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>I then save the data using the _db.SaveChanges() in my controller like so:</p>
  
  <pre><code>[Authorize]
      [HttpPost]
      public ActionResult Create(CreateNewsViewModel input)
      {
          if (ModelState.IsValid)
          {
              var news = new NewsItem();
              news.NewsTitle = input.nTitle;
              news.NewsContent = input.nContent;
              news.DateAdded = input.nDateAdded;
              news.IsLive = input.nIsLive;
              Mydb data = new Mydb();
              data.NewsItems.Add(news);
              data.SaveChanges();
              return View("Index", data.NewsItems);
  
          }
          else
          {
              return View(input);
          }
      }
  </code></pre>
  
  <p>Currently I don't have an image upload bit. How would I go about this? In my db I have a binary field, and my data type in my object is a byte[]. But I don't know where I need to handle the Image Upload?</p>
  
  <p>Do I need a seperate action that returns the view? Some pointers on this would be grand. </p>
  
  <p>Cheers</p>