title: Preselect Items in Multiselect-Listbox (MVC3 Razor)
body: <p>I have a problem with the preselection of Items in a listbox.
  I am using razor view engine with mvc 3. I know there are a few posts with the same issue but they don't work for me.</p>
  
  <p>Code in Class:</p>
  
  <pre><code>public class Foo{
      private int _id;
      private string _name;
  
      public string Name{
         get{
             return _name;
         }
  
      public int Id {
         get{
             return _id;
         }
  
  }
  </code></pre>
  
  <p>Code in Model: </p>
  
  <pre><code>public class FooModel{
  
      private readonly IList&lt;Foo&gt; _selectedFoos;
      private readonly IList&lt;Foo&gt; _allFoos;
  
      public IList&lt;Foo&gt; SelectedFoos{
           get{ return _selectedFoos;}
      }
  
      public IList&lt;Foo&gt; AllFoos{
           get{ return _allFoos;}
      }
  
  }
  </code></pre>
  
  <p>Code in cshtml:</p>
  
  <pre><code> @Html.ListBoxFor(model =&gt; model.Flatschels, 
          Model.AllFlatschels.Select(fl =&gt; new SelectListItem {
               Text = fl.Name,
               Value = fl.Id.ToString(),
               Selected = Model.Flatschels.Any(y =&gt; y.Id == fl.Id)
     }), new {Multiple = "multiple"}) 
  </code></pre>
  
  <p>I tried lots of other things but nothing worked. Hope someone can help.</p>