title: Simple static drop down example
body: <p>I am learning ASP.NET MVC 5 EF with Scaffolding, and am trying to come up with a simple static drop down choice list.  </p>
  
  <p>I have a client, and would like a drop-down choice list of states.   For now, I would like the list to be hard-coded.</p>
  
  <p>So far, I have figured out if I create a State model class with a "StateID" property, and add the same StateID to my Client class, scaffolding recognizes it as a foreign key.   However, there are no choices in the drop down.</p>
  
  <pre><code>public string stateID { get; set; }
  </code></pre>
  
  <p>I think my issue is how to populate the list of state objects somewhere for scaffolding.   All the examples online I can find are adding code to either the controller or view.   The problem there, is when I regenerate my scaffolding off my model, my view and controller code is going to regenerate.  This IS what I want, I just need to know how to populate the static data in the model, or similar?</p>
  
  <p>I tried creating this class based on some research, but I think it's either not correct, or I need to somehow call the GetStates() in my Clinet model?</p>
  
  <pre><code>public class State
      {
          public string StateID { get; set; }
          public string Name { get; set; }
  
          public static IQueryable&lt;State&gt; GetStates()
          {
              return new List&lt;State&gt;
              {
                  new State {
                      StateID = "MA",
                      Name = "Massachusetts"
                  },
                  new State{
                      StateID = "CT",
                      Name = "Conneticuit"
                  },
                  new State{
                      StateID = "RI",
                      Name = "Rhode Island"
                  },
                  new State{
                      StateID = "NH",
                      Name = "New Hampshire"
                  }
              }.AsQueryable();
          }
      }
  </code></pre>
  
  <p>This is the automatically generated scaffold view (which I am thinking I should not modify so that I am able to re-scaffold):</p>
  
  <pre><code>@model IEnumerable&lt;MBDApp.Models.Client&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.firstName)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.lastName)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.StateID)
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.firstName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.lastName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.StateID)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
              @Html.ActionLink("Details", "Details", new { id=item.id }) |
              @Html.ActionLink("Delete", "Delete", new { id=item.id })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  </code></pre>