title: Fill Dropdownlist with values from database - MVC4
body: <p>i have a table in my database which i select all rows to fill it in my dropdownlist in my view.</p>
  
  <p>i can´t understand how can i fill the values in there.</p>
  
  <p>someone can give me a hand?</p>
  
  <p>My code:</p>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>public class MyList
      {
          public int id { get; set; }
          public string name{ get; set; }
      }
  
      public class Empresas
      {
          public static IEnumerable&lt;MyList&gt; Getmyinformation()
          {
              var list = new List&lt;MyList&gt;();
              string connection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
  
              using (var con = new SqlConnection(connection))
              {
                  con.Open();
                  using (var command = new SqlCommand("SELECT * FROM mytable", con))
                  {
                      SqlDataReader reader = command.ExecuteReader();
                      while (reader.Read())
                      {
                          string Name= reader[1] as string;
                          list.Add(new MyList() { name= Name});
                      }
                  }
                  con.Close();
              }
              return list;
          }
      }
  
      public class DefaultConnection : DbContext
      {
         public DbSet&lt;MyList&gt; lat { get; set; }  
      }
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>private DefaultConnection db = new DefaultConnection();
   public ActionResult Add()
          {
              return View(db.lat.ToList());
          }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <p><code>@Html.DropDownListFor("-- Select --", new SelectList(""))</code> &lt;=== ???? i dont know </p>