I have a model that was auto-generated from my SQL database.
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; }
}
In my Organization View, on my Index page – it is strongly typed to my Organization Model.
I am trying to displaying the Membership information, on the Organization index page, that I believe should be in the ICollection. Unless I am miss-interpreting what that does.
When I go to put a @Html.DisplayFor(modelItem => item.OrganizationMemberships. to grab the data in the OrganizationMembership table, it does not show up on IntelliSense. I only need to be able to display the data, I don’t have to submit any changes with a form.
Since the model is an enumerable type —
@model PagedList.IPagedList<VAGTC.Models.Organization>— you’ll need to iterate through them in your main view:Next, create a display template for the class
Organization. UnderViews/Shared/DisplayTemplatesadd a viewOrganization.cshtml:Now this is the main view that renders your class. Here you can iterate over the membership items:
Now again, create a partial view for the
OrganizationMembershipclass by addingOrganizationMembership.cshtmlunderViews/Shared/DisplayTemplates.