【发布时间】:2013-08-09 20:21:27
【问题描述】:
我有一个强类型视图,其中有一个基于模型联系人的表单。在文本框中,默认值是我传递给控制器视图的联系人的值。 所以我有一个类 Contact 如下:
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;
}
}
有一个FonctionContact列表。 FonctionContact 的类:
public class FonctionContact
{
public int IdFonction;
public string LibelleFonction;
public FonctionContact() { }
public FonctionContact(int idFonction, string libelleFonction)
{
this.IdFonction = idFonction;
this.LibelleFonction = libelleFonction;
}
}
所以我想在 listBoxfor 中显示联系人的 ListeFonctions 属性,但它不起作用。我尝试在表单中显示列表:
@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"));
}
它向我显示一个错误:“Model.FonctionContact 没有属性 IdFonction。所以我被困在这里,我无法找出问题所在。有人有想法吗?
【问题讨论】:
标签: c#-4.0 asp.net-mvc-4 html.listboxfor