Wie füllen Sie ein Listenfeld basierend auf einer Liste ein Modell in asp.net mvc4?

Habe ich eine stark typisierte Sicht, wo ich ein Formular basierend auf einem Modell Kontakt. In die Textfelder werden die default-Werte sind die von dem Kontakt, dass ich mich übergeben um den view im controller.
Also ich habe eine Klasse Kontakt wie folgt:

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<FonctionContact> ListeFonctions = new List<FonctionContact>();
        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<FonctionContact> 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;
        }
    }

Gibt es eine Liste von FonctionContact. Die Klasse von FonctionContact:

public class FonctionContact
{
    public int IdFonction;
    public string LibelleFonction;

    public FonctionContact() { }

    public FonctionContact(int idFonction, string libelleFonction)
    {
        this.IdFonction = idFonction;
        this.LibelleFonction = libelleFonction;
    }
}

Also ich würde gerne die Anzeige der Eigenschaft ListeFonctions der Kontakt in einem listBoxfor aber es funktioniert nicht. Es ist mein Formular, wo ich versucht habe, um die Liste anzuzeigen :

@using (Html.BeginForm()){ 
     <label>Nom:</label>
     @Html.TextBoxFor(contact => contact.Nom, new { @Value = @Model.Nom })
     <label>Prénom:</label>
     @Html.TextBoxFor(contact => contact.Prenom, new { @Value = @Model.Prenom })
     ///the next controls for the next properties of class Contact...
     <label>Fonction(s):</label>
     @Html.ListBoxFor(contact => contact.ListeFonctions, new SelectList(Model.ListeFonctions, "IdFonction", "LibelleFonction"));
     }

Zeigt er mir eine Fehlermeldung: "- Modell.FonctionContact nicht eine Eigenschaft IdFonction. So bin ich hier hängengeblieben, ich kann nicht herausfinden, was falsch ist. Hat jemand eine Idee ?

Schreibe einen Kommentar