title: MVC 3 DropDownList Syntax for a View/Model/Controller
body: <p>I have looked through most of the blog postings here dealing with MVC and how to use a DropDownList with little success.</p>
  <p>I tried to mimic a post at this link but obviously not working for me: <a href="https://stackoverflow.com/questions/9689045/drop-down-menu-causing-invalid-model-state-asp-net-mvc-3">Drop-Down Menu Causing Invalid Model State. ASP.NET MVC 3</a></p>
  <p>The objective is to have a drop-down listing for a user to choose how many cars a home garage holds in the HTTP GET Create View.</p>
  <p>The error that I am presently receiving is:</p>
  <blockquote>
  <p>Compiler Error Message: CS1061:
  'MvcPropertyManagement.Models.Property' does not contain a definition
  for 'GarageId' and no extension method 'GarageId' accepting a first
  argument of type 'MvcPropertyManagement.Models.Property' could be
  found (are you missing a using directive or an assembly reference?)</p>
  <p>Line 84:          Line 85:         
  Line 86:             @Html.DropDownListFor(model =&gt; model.GarageId,
  Model.LkupGarageTypes) Line 87:<br />
  @Html.ValidationMessageFor(model =&gt; model.GarageType) Line 88:</p>
  
  </blockquote>
  <p><strong>My Model:</strong></p>
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.ComponentModel.DataAnnotations;
      using System.Web.Mvc;
      using MvcPropertyManagement.Models;
      using MvcPropertyManagement.Models.ViewModels;
  
      namespace MvcPropertyManagement.Models
      {
          public class Property
          {
              public bool Garage { get; set; }
          
              [Display(Name=&quot;Garage Capacity&quot;)]
              public string GarageType { get; set; }
      }
  </code></pre>
  <p><strong>Controller:</strong></p>
  <pre><code>    using System;
      using System.Data;
      using System.Collections.Generic;
      using System.Data.Entity;
      using System.Linq;
      using System.Web;
      using System.Web.Mvc;
      using MvcPropertyManagement.Models;
      using MvcPropertyManagement.Models.ViewModels;
  
      public ActionResult Create()
      {
          PropertyViewModel viewModel = new PropertyViewModel();
          viewModel.LkUpGarageType = new SelectList(db.LkUpGarageTypes, &quot;GarageTypeID&quot;,         &quot;LkUpGarageType&quot;); 
          return View(viewModel);
      } 
  </code></pre>
  <p><strong>PropertyViewModel:</strong></p>
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Mvc;
      using MvcPropertyManagement.Models;
  
      namespace MvcPropertyManagement.Models.ViewModels
      {
          public class PropertyViewModel
          {
              public int? GarageId { get; set; }
              public IEnumerable&lt;SelectListItem&gt; LkUpGarageType { get; set; }        
          }
      }
  </code></pre>
  <p><strong>Create View:</strong></p>
  <pre><code>&lt;div class=&quot;editor-field&quot;&gt;
      @Html.DropDownListFor(model =&gt; model.GarageId, Model.LkupGarageTypes)
      @Html.ValidationMessageFor(model =&gt; model.GarageType)
  &lt;/div&gt;
  </code></pre>