1

我有一个从我的 SQL 数据库自动生成的模型。

class Organization
{
    public Organization()
    {
        this.ContactTitles = new HashSet<ContactTitle>();
        this.OrganizationAddresses = new HashSet<OrganizationAddress>();
        this.OrganizationBusinessTypes = new HashSet<OrganizationBusinessType>();
        this.OrganizationCountries = new HashSet<OrganizationCountry>();
        this.OrganizationEmails = new HashSet<OrganizationEmail>();
        this.OrganizationMemberships = new HashSet<OrganizationMembership>();
        this.OrganizationNotes = new HashSet<OrganizationNote>();
        this.OrganizationPhones = new HashSet<OrganizationPhone>();
        this.OrganizationWebsites = new HashSet<OrganizationWebsite>();
        this.Contacts = new HashSet<Contact>();
        this.OrganizationIndustryCodes = new HashSet<OrganizationIndustryCode>();
    }

    public int OrganizationID { get; set; }
    public string Name { get; set; }

    public virtual ICollection<ContactTitle> ContactTitles { get; set; }
    public virtual ICollection<OrganizationAddress> OrganizationAddresses { get; set; }
    public virtual ICollection<OrganizationBusinessType> OrganizationBusinessTypes { get; set; }
    public virtual ICollection<OrganizationCountry> OrganizationCountries { get; set; }
    public virtual ICollection<OrganizationEmail> OrganizationEmails { get; set; }
    public virtual ICollection<OrganizationMembership> OrganizationMemberships { get; set; }
    public virtual ICollection<OrganizationNote> OrganizationNotes { get; set; }
    public virtual ICollection<OrganizationPhone> OrganizationPhones { get; set; }
    public virtual ICollection<OrganizationWebsite> OrganizationWebsites { get; set; }
    public virtual ICollection<Contact> Contacts { get; set; }
    public virtual ICollection<OrganizationIndustryCode> OrganizationIndustryCodes { get; set; }
 }

在我的组织视图中,在我的索引页面上 - 它被强输入到我的组织模型中。

我正在尝试在组织索引页面上显示我认为应该在 ICollection 中的成员资格信息。除非我误解了它的作用。

当我去@Html.DisplayFor(modelItem => item.OrganizationMemberships.获取OrganizationMembership 表中的数据时,它不会显示在IntelliSense 上。我只需要能够显示数据,我不必使用表单提交任何更改。

4

1 回答 1

3

由于模型是一个可枚举类型——@model PagedList.IPagedList<VAGTC.Models.Organization>你需要在你的主视图中遍历它们:

@foreach (var organization in Model)
{
    @Html.DisplayFor(model => organization)
} 

接下来,为类创建一个显示模板Organization。在Views/Shared/DisplayTemplates添加视图下Organization.cshtml

@model VAGTC.Models.Organization

现在这是呈现您的课程的主要视图。在这里,您可以迭代成员项目:

@foreach (var membership in Model.OrganizationMemberships)
{
    @Html.DisplayFor(model => membership)
} 

现在再次OrganizationMembership通过OrganizationMembership.cshtmlViews/Shared/DisplayTemplates.

于 2012-11-16T23:05:12.867 回答