title: Asp.net identity add drop down list to default register view
body: <p>I'm trying to learn add a drop down menu to the registration page using ASP.NET identity. I can get the drop down to show up when it's the only element in a view, but when I try to add it the the default 'Register' view, I'm getting an error:</p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Identity.Web.Models.Countries]', but this dictionary requires a model item of type 'Identity.Web.Models.RegisterViewModel'.</p>
  </blockquote>
  
  <p>Here is what works by itself:</p>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>public class Countries
  {
      public string Country { get; set; }
      public string CountryAbbr { get; set; }
      //for drop down menu
      public SelectList CountryList { get; set; } 
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>@model DDL_Test3.Models.Countries
  @{ViewBag.Title = "DropDown"}
  
  @Html.DropDownListFor(model =&gt; model.Country,
  new SelectList(ViewBag.CountryList, "CountryAbbr", "Country"), "--Select a Country --", new { @class = "form-control" })
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>    public ActionResult DropDown()
      {
          List&lt;Countries&gt; model = SQLConnection.ddlGetAllCountries();
          ViewBag.CountryList = model;
          return View();
      }
  
      public static List&lt;Countries&gt; ddlGetAllCountries()
      {
          using (var connection = new SqlConnection(SQLConnection.GetConnectionString()))
          {
              return connection.Query&lt;Countries&gt;("sp_GetAllCountries", commandType: CommandType.StoredProcedure).ToList();
          }
      }
  </code></pre>
  
  <p>I guess what I'm confused about, is how do I get the drop down list added to the default 'RegisterViewModel', show below:</p>
  
  <pre><code>public class RegisterViewModel
  {
      [Required]
      [Display(Name = "UserName")]
      public string UserName { get; set; }
  
      [Required]
      [EmailAddress]
      [Display(Name = "Email")]
      public string Email { get; set; }
  
      [Required]
      [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
      [DataType(DataType.Password)]
      [Display(Name = "Password")]
      public string Password { get; set; }
  
      [DataType(DataType.Password)]
      [Display(Name = "Confirm password")]
      [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
      public string ConfirmPassword { get; set; }
  
      [Display(Name = "Select a Country")]
      public string Country { get; set; }
      public string CountryAbbr { get; set; }
      //drop down list
      public System.Web.Mvc.SelectList CountryList { get; set; } 
  
  } 
  </code></pre>
  
  <p><strong>UPDATED</strong></p>
  
  <p>Here is the missing controller:</p>
  
  <pre><code>    // GET: /Account/Register
      [AllowAnonymous]
      public ActionResult Register()
      {
          List&lt;Countries&gt; model = EntityData.ddlGetAllCountries();
          ViewBag.CountryList = model;
  
          return View(model);
      }
  </code></pre>
  
  <p>Here is the @RegisterViewModel view:</p>
  
  <pre><code>@model Identity.Web.Models.RegisterViewModel
  @{
      ViewBag.Title = "Register";
  }
  
  &lt;h2&gt;@ViewBag.Title.&lt;/h2&gt;
  
  @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
  {
      @Html.AntiForgeryToken()
      &lt;h4&gt;Create a new account.&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary("", new { @class = "text-danger" })
      &lt;div class="form-group"&gt;
          @Html.LabelFor(m =&gt; m.UserName, new { @class = "col-md-2 control-label" })
          &lt;div class="col-md-10"&gt;
              @Html.TextBoxFor(m =&gt; m.UserName, new { @class = "form-control" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          @Html.LabelFor(m =&gt; m.Email, new { @class = "col-md-2 control-label" })
          &lt;div class="col-md-10"&gt;
              @Html.TextBoxFor(m =&gt; m.Email, new { @class = "form-control" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          @Html.LabelFor(m =&gt; m.Password, new { @class = "col-md-2 control-label" })
          &lt;div class="col-md-10"&gt;
              @Html.PasswordFor(m =&gt; m.Password, new { @class = "form-control" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          @Html.LabelFor(m =&gt; m.ConfirmPassword, new { @class = "col-md-2 control-label" })
          &lt;div class="col-md-10"&gt;
              @Html.PasswordFor(m =&gt; m.ConfirmPassword, new { @class = "form-control" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          @Html.LabelFor(m =&gt; m.Country, new { @class = "col-md-2 control-label" })
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor(model =&gt; model.Country, new SelectList(ViewBag.CountryList, "CountryAbbr", "Country"), "--Select a Country --", new { @class = "form-control" })
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" class="btn btn-default" value="Register" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  
  @section Scripts {
      @Scripts.Render("~/bundles/jqueryval")
  }
  </code></pre>