title: Get data from the database using mvc
body: <p>I am trying to retrieve data from the database and populate the records in a table, but i am getting an error <code>An exception of type 'System.NullReferenceException' occurred in App_Web_14paz0pq.dll but was not handled in user code
  Additional information: Object reference not set to an instance of an object.</code> I get this error when running my project, my view dont even show-up in web-browser. This is my model:</p>
  
  <pre><code>public class MovieModel
  {
      public int ID { set; get; }
      [DisplayName("First Name")]
      public string FirstName { set; get; }
      [DisplayName("Second Name")]
      public string SecondName { set; get; }
      [DisplayName("Date Of Birth")]
      public DateTime DOB { set; get; }
      [DisplayName("Other Info")]
      public string Other{ set; get; }
  }
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>namespace Movie.Controllers
  {
      public class MoviesController : Controller
      {
  
          private ApplicationDbContext db = new ApplicationDbContext();
  
          public ActionResult GetList() {
          return View();
          }
  
          [HttpPost]
          public ActionResult GetList(MovieModel model)
          {
              var data = db.Movies.ToList();
              return View(data);
          }
      }
  }
  </code></pre>
  
  <p>This is my View:</p>
  
  <pre><code>@model IEnumerable&lt;Movie.Models.MovieModel&gt;
  
  @{
     ViewBag.Title = "";
   Layout = "~/Views/Shared/_Layout.cshtml";
      }  
  
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
   &lt;/p&gt;
     &lt;table class="table"&gt;
      &lt;tr&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.FirstName)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.SecondName)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.DOB)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.Other)
      &lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
  &lt;/tr&gt;
  
  
  
  @foreach (var item in Model) {
  &lt;tr&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.FirstName)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.SecondName)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.DOB)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.Other)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
          @Html.ActionLink("Details", "Details", new { id=item.ID }) |
          @Html.ActionLink("Delete", "Delete", new { id=item.ID })
      &lt;/td&gt;
  &lt;/tr&gt;
      }
  
  &lt;/table&gt;
  </code></pre>
  
  <p>I am getting this error in this line <code>@foreach (var item in Model) {</code></p>