title: ASP.NET MVC 4 ViewModel with DropDownList data
body: <p>I'm using <code>@html.EditorFor</code> to render my model in edit mode, and a dropdownlist is not rendered.</p>
  
  <p>Here's my ViewModel:</p>
  
  <pre><code>     public class RiskAutoViewModel
       {
         public RiskAutoViewModel()
         {
           VehicleMakeList = new SelectList(new List&lt;VehicleMake&gt;() { new VehicleMake() { Id = 1, Name = "Renault" }, new VehicleMake() { Id = 2, Name = "Peugeot" } });
         }
  
  
      public int NoClaimsDegree { get; set; }
  
      public int VehicleValue { get; set; }
  
      public int EngineCapacity { get; set; }
  
      public int VehicleMake { get; set; }
  
      public SelectList VehicleMakeList { get; set; }
    }
  </code></pre>
  
  <p><code>VehicleMake</code> is rendered as a <em>textbox</em> and <code>VehicleMakeList</code> is not rendered at all. What I'd like is to render a dropdownlist containing the list of <code>VehicleMake</code> and set its value to the one of <code>VehicleMake</code>. </p>
  
  <p>When the model is saved, VehicleMake should be set to the value of the selected item in the list.</p>
  
  <p>How can I do that ? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Since I can't type any code in the comment boxes below, I'll write a follow up here.</p>
  
  <p>I ended up creating a EditorTemplate such as:</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.VehicleMakeList)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.DropDownListFor(model =&gt; model.VehicleMake, Model.VehicleMakeList)
      @Html.ValidationMessageFor(model =&gt; model.VehicleMake)
  &lt;/div&gt;
  </code></pre>
  
  <p>And now my ViewModel looks like this:</p>
  
  <pre><code>[Required]
  [ScaffoldColumn(false)]
  public int VehicleMake { get; set; }
  
  [Display(Name = "Marque", Prompt = "Marque", Description = "Renseigne la marque du véhicule")]
  public SelectList VehicleMakeList { get; set; }
  </code></pre>
  
  <p>Now this leads me to another question (maybe I should as in a different thread) but I actually have TWO dropdowns in that View. And the items in the second dropdown are basically dynamic and they depend on the item selected in the first dropdown. This is dead easy to do with AJAX but with MVC I'm lost. How do people do that usually ?</p>