title: Populating razor DropDownList from view model
body: <p>I have a custom model (let's say CustomModel) for populating my razor DropDownList in the view:</p>
  
  <pre><code>namespace MyNamespace.Models
  {
      public class SelectListItem
      {
          public string Value { get; set; }
          public string Text { get; set; }
      }
  
      public class ComponentTypeModel
      {
          private readonly List&lt;ComponentType&gt; componentTypes;
  
          [Display(Name = "Component Type")]
          public int SelectedCompTypeId { get; set; }
  
          public IEnumerable&lt;SelectListItem&gt; CompTypeItems
          {
              get
              {
                  var allCompTypes = componentTypes.Select(f =&gt; new SelectListItem
                  {
                      Value = f.Id.ToString(),
                      Text = f.Name
                  });
  
                  return allCompTypes;
              }
          }
  
          public IEnumerable&lt;SelectListItem&gt; DefaultCompTypeItem
          {
              get
              {
                  return Enumerable.Repeat(new SelectListItem
                                                 {
                                                     Value = "-1",
                                                     Text = "Select a component type"
                                                 }, 
                                           count: 1);
              }
  
          }
      }
  }
  </code></pre>
  
  <p>Then in my view I do the following using razor:</p>
  
  <pre><code>@model MyNamespace.Models.CustomModel
  
  @Html.LabelFor(m =&gt; m.SelectedCompTypeId);
  @Html.DropDownListFor(m =&gt; m.SelectedCompTypeId, Model.CompTypeItems);
  </code></pre>
  
  <p>but the second argument <strong>Model.CompTypeItems</strong> in line:</p>
  
  <pre><code>@Html.DropDownListFor(m =&gt; m.SelectedCompTypeId, Model.CompTypeItems);
  </code></pre>
  
  <p>is generating a compilation error saying that it is not valid. Any ideas?</p>