title: asp.net mvc ObjectDisposedException with ef
body: <p>I need some help with this error "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."</p>
  
  <p>It's a asp.net mvc3, EF4, and ms sql.
  Here is the razor with two dropdowns:</p>
  
  <pre><code>&lt;div class="editRow"&gt;
  @Html.DropDownListFor(m=&gt;m.IndustryId, (SelectList)ViewBag.Industry, @Empower.Resource.General.ddlDefaultVal, new { @class = "ddl400" })
  @Html.ValidationMessageFor(m =&gt; m.IndustryId)
  &lt;/div&gt;
  &lt;div class="editRow"&gt;
  @Html.DropDownListFor(m=&gt;m.ProvinceId, (SelectList)ViewBag.Province, @Empower.Resource.General.ddlDefaultVal, new {@class = "ddl400"})
   @Html.ValidationMessageFor(m =&gt; m.ProvinceId)   
  &lt;/div&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code> IndustryService indService = new IndustryService();
  ViewBag.Industry = new SelectList(indService.GetAllIndustry(), "IndustryId", "IndustryName");
  ProvinceService proService = new ProvinceService();
  ViewBag.Province = new SelectList(proService.GetAllProvince(), "ProvinceId", "ProvinceName");
   return View();
  </code></pre>
  
  <p>ProvinceService:</p>
  
  <pre><code>public IEnumerable&lt;Province&gt; GetAllProvince()
          {
              using (var context = DBContext.ObjectContext)
              {
                  var pros = context.Provinces;
                  return pros;
              }
          }
  </code></pre>
  
  <p>IndustryService is identical as above...</p>
  
  <pre><code>public class DBContext
      {
          private static EmpowerDBEntities _empowerContext;
          public static EmpowerDBEntities ObjectContext
          {
              get
              {
                  if (_empowerContext == null)
                      _empowerContext = new EmpowerDBEntities();
                  return _empowerContext;
              }
          }
      }
  </code></pre>
  
  <p>I know the problem occurs in second dropdown when it tries to retrive data while the connection is desposed by previous query. Please help me with this, thanks.</p>