title: MVC: MultiSelectList Object reference not set to an instance of an object
body: <p>I'm trying to bind a ListBox in my partial view but I'm getting the exception...</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>Referencing <code>@Html.ListBoxFor(x =&gt; x.SelectedRoles, Model.Roles)</code></p>
  
  <p>I'm not sure what I'm doing wrong...</p>
  
  <p>Model:</p>
  
  <pre><code>public class RegisterModel {
      public string UserName { get; set; }
      public string Email { get; set; }
      public string Password { get; set; }
      public string ConfirmPassword { get; set; }
      public string[] SelectedRoles { get; set; }
      public MultiSelectList Roles { get; set; }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class AdminController : Controller  {
      [ChildActionOnly]
      public ActionResult _AddUser() {
          var model = new RegisterModel {
              Roles = new MultiSelectList(Roles.GetAllRoles())
          };
  
          return View(model);
      }
  
  }
  </code></pre>
  
  <p>PartialView _AddUser.cshtml:</p>
  
  <pre><code>@model RobotDog.Models.RegisterModel
  
  @using(Html.BeginForm("_AddUser","Admin", FormMethod.Post)) {
      @Html.EditorFor(x =&gt; x.Email, new { @class = "input-xlarge", @placeholder = "Email"})
      @Html.EditorFor(x =&gt; x.UserName, new { @class = "input-xlarge", @placeholder = "User Name"})
      @Html.EditorFor(x =&gt; x.Password, new { @class = "input-xlarge", @placeholder = "Password"})
      @Html.ListBoxFor(x =&gt; x.SelectedRoles, Model.Roles)
  }
  </code></pre>
  
  <p>Here is the view that is referencing _AddUser.cshtml
  Users.cshtml:</p>
  
  <pre><code>@model IEnumerable&lt;RobotDog.Models.UserModel&gt;
  &lt;table&gt;&lt;/table&gt;
  &lt;div id="addUser"&gt;
      @Html.Partial("_AddUser", new ViewDataDictionary())
  &lt;/div&gt;
  </code></pre>