title: Encountering 'Object reference not set to an instance of an object' error when editing record
body: <p>Hi i am trying to figure out why i get this error only when i try to edit a record in the database but the code has nothing to do with the edit update code. This code that is used to run a stored procedure that is used to pull groups and put the names into a list. It works if you add a record or add multiple records.</p>
  
  <pre><code>List&lt;String&gt; groups = new List&lt;String&gt;(); 
  
  groups = db.spGetCurrentInsuranceGroups().ToList();
  
  /* This where the stored procedure is being called to populate the insurance groups*/
  foreach (String group in groups)
  {
      &lt;option value="@group"&gt;@group&lt;/option&gt;
  }
  </code></pre>
  
  <p>here are images of adding a new record and editing. it populates the dropdown list. but if you click select then it wants to give a problem.</p>
  
  <p><a href="http://i.stack.imgur.com/LcUyB.png" rel="nofollow">adding new record</a></p>
  
  <p><a href="http://i.stack.imgur.com/fIsR9.png" rel="nofollow">editing record</a></p>
  
  <p>as you can see it populates the insurance part that is giving it a problem if you hit the submit to update the record.</p>
  
  <p>here is the error page i get</p>
  
  <blockquote>
    <p>Server Error in '/' Application. Object reference not set to an
    instance of an object. Description: An unhandled exception occurred
    during the execution of the current web request. Please review the
    stack trace for more information about the error and where it
    originated in the code.</p>
    
    <p>Exception Details: System.NullReferenceException: Object reference not
    set to an instance of an object.</p>
    
    <p>Source Error:</p>
    
    <p>Line 202: foreach (var group in groups.OfType().ToList())  </p>
    
    <p>Stack Trace:</p>
    
    <p>[NullReferenceException: Object reference not set to an instance of an
    object.]    System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
    +271    System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +112    System.Web.WebPages.WebPage.ExecutePageHierarchy()
    +128    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext
    pageContext, TextWriter writer, WebPageRenderingBase startPage) +131<br>
    System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase
    httpContext) +178</p>
  </blockquote>
  
  <p><strong>Version Information:</strong> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.81.0 </p>