title: Dropdown in MVC
body: <p>In my MVC application, I need to add a dropdown that would show a list of domain names.</p>
  
  <p>I already have a ViewModel that contains multiple properties. I am not sure what the sequence of the steps should be:</p>
  
  <ol>
  <li>Add a new property to my <code>ViewModel</code>? What should be the type? List?</li>
  <li>Define a method that populates the above property with values.</li>
  <li>Use that property in the View? Use <code>HTML.DropdownFor</code>?</li>
  </ol>
  
  <p>I know I should put some code in my Question, but right now I am having difficulty getting started with this...</p>
  
  <p><strong>EDIT:</strong>
  Added the following property to the ViewModel:</p>
  
  <pre><code> public IEnumerable&lt;SelectListItem&gt; DomainList { get; set; }
  </code></pre>
  
  <p>and implemented a method to return a list of Domains:</p>
  
  <pre><code>internal static List&lt;Domain&gt; FetchAllDomains()
  </code></pre>
  
  <p>Next in my controller action, I have:</p>
  
  <pre><code>var domains = FetchAllDomains().Select(d =&gt; d.DomainName);
  return new EmailModel() {DomainList = domains };
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type
    'System.Collections.Generic.IEnumerable' to
    'System.Collections.Generic.IEnumerable'.
    An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>