title: ListBoxFor MultiSelectList does not select values
body: <p>I'm incredibly confused, because this seems like it should be simple but I can't get my <code>ListBox</code> to be populated with selected values. I've looked at several other answers and I can't figure out what I'm doing wrong.</p>
  
  <p>This is my model:</p>
  
  <pre><code>public class ItemViewModel
  {
      public IEnumerable&lt;Item&gt; AllItems { get; set; }
      public IEnumerable&lt;Item&gt; SelectedItems { get; set; }
  }
  
  public class Item
  {
      public string Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>This is my controller action:</p>
  
  <pre><code>public ActionResult ListBoxTest()
  {
      var viewModel = new ItemViewModel()
      {
          AllItems = new List&lt;Item&gt;()
          {
              new Item()
              {
                  Id = "1",
                  Name = "Name1"
              },
              new Item()
              {
                  Id = "2",
                  Name = "Name2"
              }
          },
          SelectedItems = new List&lt;Item&gt;()
          {
              new Item()
              {
                  Id = "1",
                  Name = "Name1"
              }
          }
      };
      return this.View(viewModel);
  }
  </code></pre>
  
  <p>And this is the line in my view (using a default MVC View template):</p>
  
  <pre><code>@Html.ListBoxFor(m =&gt; m.SelectedItems, new MultiSelectList(Model.AllItems, "Id", "Name", Model.SelectedItems.Select(s =&gt; s.Id)), new { multiple = "multiple"})
  </code></pre>
  
  <p>I've also tried omitting the selected values:</p>
  
  <pre><code>@Html.ListBoxFor(m =&gt; m.SelectedItems, new MultiSelectList(Model.AllItems, "Id", "Name"), new { multiple = "multiple"})
  </code></pre>
  
  <p>And making the selected values a list:</p>
  
  <pre><code>@Html.ListBoxFor(m =&gt; m.SelectedItems, new MultiSelectList(Model.AllItems, "Id", "Name", Model.SelectedItems.Select(s =&gt; s.Id).ToList()), new { multiple = "multiple"})
  </code></pre>
  
  <p>But no matter what I do, the list items are never selected. What am I doing wrong?</p>