title: ASP.NET MVC 2 - How do I use DropDownListFor?
body: <p>I have a simple model / view with things like Username, Password etc. and use helpers fine to hook it up.</p>
  
  <p>I now have a field called "NumberOfChildren". I want to store a number in it (int) and I want it render a dropdown box containing "None", "1", "2" etc.</p>
  
  <p>My thoughts would be that the model would have a list or a method that returns a list, so I can specify the values such as NumberOfChildren_List that I put the data into, and then DropDownListFor pulls that list and renders it, matching the value to the value of the item in the dropdown.</p>
  
  <p>However after spending about 30 minutes on trying to figure out how on earth it works, I gave up and decided to ask here. Any ideas?</p>
  
  <p>Edit: Here's some code...</p>
  
  <pre><code>&lt;%: Html.DropDownListFor(m =&gt; m.NumberOfChildren, new SelectList(Model.NumberOfChildrenListValues))%&gt;
  </code></pre>
  
  <p>and in the model</p>
  
  <pre><code>        [Required]
          [DisplayName("How many children do you have?")]
          public string NumberOfChildren { get; set; }
  
          public IEnumerable&lt;string&gt; NumberOfChildrenListValues
          {
              get
              {
                  List&lt;string&gt; list = new List&lt;string&gt;() { "None", "1", "2" };
  
                  return list;
              }
  
              set
              {
  
              }
  
          }
  </code></pre>
  
  <p>I get an object not set to instance of object error though. Ideas?</p>