views:

575

answers:

1

Hi folks

Im new to MVC and EF. I have a basic app that lists info from a few (4) tables relating to some servers. One of the relationships is a many to many (Servers to Roles).

I pass my ViewData to the View by making use of this in the controller:

ViewData.Model = (from s in _db.Servers.Include("Locations").Include("OperatingSystems").Include("Roles")
                          select s).ToList();

However im not sure how to go about displaying the multiple roles for each server in my View?

+2  A: 

Suppose your ViewData.Model works and the Model is of List type.

<% foreach (var server in Model)
{%>
    <% foreach (var role in server.Roles)
    {%>
    <li><%= role.Name %></li>
    <%}%>
<%}%>
rokeyge