title: Registration form with roles MVC3, Error: ViewData item is of type "system.sting" must be "IEnumerable<selectlistitem>
body: <p>I'm using MVC3 with razor and I wanna make a registration form where I can choose role with a dropdownlist.</p>
  
  <p>I get the roles in the dropdown list and all that but when i click submit i get:</p>
  
  <p>The <code>ViewData</code> item that has the key 'Role' is of type <code>System.String</code> but must be of type <code>IEnumerable&lt;SelectListItem&gt;</code>.</p>
  
  <p>My code</p>
  
  <p>Model:</p>
  
  <pre><code>[Required]
      [Display(Name = "Select role: ")]
      public String Role { get; set; }
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>public ActionResult Register()
      {
          List&lt;SelectListItem&gt; list = new List&lt;SelectListItem&gt;();
          SelectListItem item;
          foreach (String role in Roles.GetAllRoles())
          {
              item = new SelectListItem{ Text = role, Value = role};
              list.Add(item);
          }
  
          ViewBag.roleList = (IEnumerable&lt;SelectListItem&gt;)list;
          return View();
      }
  </code></pre>
  
  <p>My post controller:</p>
  
  <pre><code>[HttpPost]
      public ActionResult Register(RegisterModel model)
      {
          if (ModelState.IsValid)
          {
              // Attempt to register the user
              MembershipCreateStatus createStatus;
              Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
  
              if (createStatus == MembershipCreateStatus.Success)
              {
                  Roles.AddUserToRole(model.UserName, model.Role);
                  return RedirectToAction("Index", "Home");
              }
              else
              {
                  ModelState.AddModelError("", ErrorCodeToString(createStatus));
              }
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
              @Html.LabelFor(m =&gt; m.Role)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.DropDownListFor(m =&gt; m.Role, ViewBag.roleList as IEnumerable&lt;SelectListItem&gt;)
              @Html.ValidationMessageFor(m =&gt; m.Role)
  
          &lt;/div&gt;
  </code></pre>
  
  <p>When I use the debugger to check my code, in the controller when I look on the parameter model and at <code>model.Role</code> I see the right String.
  Does anyone know any solution to my problem?</p>