title: How to bind Dropdown List in asp.net MVC from Database using Entity Framework
body: <p>I am a beginner in MVC and trying to bind drop-down list to a model using data from a database lookup table.</p>
  
  <p>My Model:</p>
  
  <pre><code> public class State
  {
      [Required]
      public string StateName { get; set; }
      public int CountryId { get; set; }
      public List&lt;SelectListItem&gt; CountryList { get; set; }
  
  }
  </code></pre>
  
  <p>In my Controller:</p>
  
  <pre><code>[HttpGet]
  public ActionResult AddState()
  {
      State obj = new State();
      using (MvcWorkEntities context = new MvcWorkEntities())
      {
          obj.CountryList = context.Mst_Country.ToList();
      }
      return View(obj);
  }
  </code></pre>
  
  <p>The View:</p>
  
  <pre><code>@using(Html.BeginForm("AddState","Home",FormMethod.Post))
  { 
  &lt;div class="col-md-4"&gt;
      &lt;div class="form-group"&gt;
          @Html.Label("Select Country")
        @Html.DropDownListFor(m=&gt;m.CountryId,Model.CountryList);
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="col-md-4"&gt;
      &lt;div class="form-group"&gt;
          @Html.Label("Enter State Name")
          @Html.TextBoxFor(m=&gt;m.StateName)
      &lt;/div&gt;
  &lt;/div&gt;
  }
  </code></pre>
  
  <p>This isn't working as intended and I don't understand where I am going wrong. Could anyone point out where I might be making a mistake?</p>