title: Model Empty Null Exception Error on Delete
body: <p>I keep getting an error when trying to delete a record from my database using MVC. What does this error mean? What am I doing wrong?</p>
  
  <p>Here is my controller action:</p>
  
  <pre><code>public ActionResult Delete(int id)
  {
  
      Person somePerson = db.People
          .Where(p =&gt; p.Id == id)     //this line says to find the person whose ID matches our parameter
          .FirstOrDefault();          //FirstOrDefault() returns either a singluar Person object or NULL
  
      db.Entry(somePerson).State = System.Data.Entity.EntityState.Deleted;
      db.SaveChanges();
  
  
      return View("Index");
  }
  </code></pre>
  
  <p>Here is my View:</p>
  
  <pre><code>@using sample.Models
  @model List&lt;Person&gt;
  @{
  
      Layout = null;
  }
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      &lt;title&gt;Index&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt; 
          &lt;!-- Html.ActionLink is the MVC equivalent of &lt;a href="..."&gt;&lt;/a&gt;  
              --&gt;
          @Html.ActionLink("Create new person", "Create")
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;/th&gt;
                  &lt;th&gt;Email Address&lt;/th&gt;
                  &lt;th&gt;First Name&lt;/th&gt;
                  &lt;th&gt;Last Name&lt;/th&gt;
              &lt;/tr&gt;
  
              &lt;!-- Loop through our List of People and create a new TR for each item --&gt;
              @foreach(Person person in Model)  //Error Occurs on this line
              {
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;@Html.ActionLink("Edit", "Edit", new { id = person.Id })&lt;/td&gt;
                      &lt;td&gt;@Html.ActionLink("Delete", "Delete", new { id = person.Id })&lt;/td&gt;
                      &lt;!-- Using the @@ tag will inject the object's value into HTML --&gt;
                      &lt;td&gt;@person.Email&lt;/td&gt;
                      &lt;td&gt;@person.FirstName&lt;/td&gt;
                      &lt;td&gt;@person.LastName&lt;/td&gt;
                  &lt;/tr&gt;
              }
          &lt;/table&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Edit and Create Work Fine. When I added the delete is where i started to get the issues. Here is the exception I am getting and Model is null FYI</p>
  
  <pre><code>An exception of type 'System.NullReferenceException' occurred in App_Web_rczw3znb.dll but was not handled in user code
  </code></pre>