title: How to populate a ListBox based on a list of a model in asp.net mvc4?
body: <p>I have a strongly typed view where I have a form based on a Model Contact. In the textboxes, the default values are those of the contact that I'm passing to the view in the controller.
  So I have a class <strong>Contact</strong> as follows:</p>
  
  <pre><code>public class Contact
      {
          public int IdContact { get; set; }
          public string Nom { get; set; }
          public string Prenom { get; set; }
          public string Email { get; set; }
          public string Fonction { get; set; }
          public List&lt;FonctionContact&gt; ListeFonctions = new List&lt;FonctionContact&gt;();
          public string TelephoneFixe { get; set; }
          public string TelephonePort { get; set; }
          public Contact() { }
  
          public Contact(int idContact, string nom, string prenom, string email, string telephoneFixe, string telephonePort)
          {
              this.IdContact = idContact;
              this.Nom = nom;
              this.Prenom = prenom;
              this.Email = email;
              this.TelephoneFixe = telephoneFixe;
              this.TelephonePort = telephonePort;
          }
  
          public Contact(int idContact, string nom, string prenom, List&lt;FonctionContact&gt; listeFonctions, string email, string telephoneFixe, string telephonePort)
          {
              this.IdContact = idContact;
              this.Nom = nom;
              this.Prenom = prenom;
              this.ListeFonctions = listeFonctions;
              this.Email = email;
              this.TelephoneFixe = telephoneFixe;
              this.TelephonePort = telephonePort;
          }
      }
  </code></pre>
  
  <p>There is a list of <strong>FonctionContact</strong>. The class of FonctionContact:</p>
  
  <pre><code>public class FonctionContact
  {
      public int IdFonction;
      public string LibelleFonction;
  
      public FonctionContact() { }
  
      public FonctionContact(int idFonction, string libelleFonction)
      {
          this.IdFonction = idFonction;
          this.LibelleFonction = libelleFonction;
      }
  }
  </code></pre>
  
  <p>So I would like to display the property <strong>ListeFonctions</strong> of the Contact in a listBoxfor but it doesn't work. There is my form where I've tried to display the list :</p>
  
  <pre><code>@using (Html.BeginForm()){ 
       &lt;label&gt;Nom:&lt;/label&gt;
       @Html.TextBoxFor(contact =&gt; contact.Nom, new { @Value = @Model.Nom })
       &lt;label&gt;Prénom:&lt;/label&gt;
       @Html.TextBoxFor(contact =&gt; contact.Prenom, new { @Value = @Model.Prenom })
       ///the next controls for the next properties of class Contact...
       &lt;label&gt;Fonction(s):&lt;/label&gt;
       @Html.ListBoxFor(contact =&gt; contact.ListeFonctions, new SelectList(Model.ListeFonctions, "IdFonction", "LibelleFonction"));
       }
  </code></pre>
  
  <p>It shows me an error: "Model.FonctionContact doesn't have a property IdFonction. So I'm stuck here, I can't find out what's wrong. Somebody has an idea ? </p>