title: How to populate an dropdownlistfor from database in ASP.NET MVC 4
body: <p>As the title says I'm looking for some help in that task, I've read many tutorials about it but none of them can solved my problem which is how to load a <code>dropdownlistfor</code> from database. By far, I got the following code:</p>
  
  <pre><code>**LNClientes():**
  
  public List&lt;ENDistrito&gt; DistritoListar()
  {
      return new ADClientes().DistritoListar();
  }
  
  **ADClientes():**
  
  public List&lt;ENDistrito&gt; DistritoListar()
          {
              Database oDatabase =                      DatabaseFactory.CreateDatabase(ConfigurationManager.AppSettings["conexionBD"]);
              DbCommand odbcommand = oDatabase.GetStoredProcCommand("USP_SEL_DISTRITOS");
  
              List&lt;ENDistrito&gt; lista = new List&lt;ENDistrito&gt;();
              using (IDataReader reader = oDatabase.ExecuteReader(odbcommand))
              {
                  while (reader.Read())
                      lista.Add(new ENDistrito(reader));
              }
              return lista;
          }
  
  **Controller:**
  
   public ActionResult Registrar()
          {
              ViewBag.Message = Resources.Language.Title_Page_MC_C;
              var ListaDistrito = new LNClientes().DistritoListar();
              ViewBag.ObtenerDistrito = new SelectList(ListaDistrito, "IdDistrito", "DescripcionDistrito");
              return View();
          }
  </code></pre>
  
  <p><strong>View:</strong> </p>
  
  <pre><code>&lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.DistritoCliente)
              @Html.DropDownListFor(model =&gt; model.DistritoCliente,(SelectList)ViewBag.ObtenerDistrito,"--Seleccione--")
              @Html.ValidationMessageFor(model =&gt; model.DistritoCliente)
          &lt;/div&gt;
  </code></pre>
  
  <p>Till this point everything is ok, when i open that form the <code>dropdownlistfor</code> works but when i submit the form i got the following message: </p>
  
  <blockquote>
    <p>There is no ViewData item of type 'IEnumerable' that
    has the key 'DistritoCliente'.</p>
  </blockquote>
  
  <p>Any idea on what I'm doing wrong or how could i solve this problem.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Alex</p>