title: MVC and Entity Framework Select List
body: <p>I have an MVC app that I am trying to put together that requires some select lists and drop down lists.</p>
  
  <p>So, I have the following models....</p>
  
  <pre><code>public class Task
  {
      public int ID { get; set; }
      public string Title { get; set; }
      ......
      public virtual ICollection&lt;Monitor&gt; Monitors { get; set; }
      public virtual ICollection&lt;Resource&gt; Resources { get; set; }
  
  }
  public class Monitor
  {
      public int ID { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
  
      public IList&lt;Task&gt; Tasks { get; set; }
  }
      public class Resource
  {
      public int ID { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      .....
  
      public IList&lt;Task&gt; Tasks { get; set; }
  </code></pre>
  
  <p>The interesting part is that when I display a list of tasks, among the other properties that display just fine, I need to display a list of 'Monitors' and a list of 'Resources' that are assigned to the task in the Index view shown below.</p>
  
  <pre><code>@model IEnumerable&lt;ResourceManager.Models.Task&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table&gt;
      &lt;tr&gt;
          .....
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Title)
          &lt;/th&gt;
          .....
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Monitors)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Resources)
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (var item in Model) {
      &lt;tr&gt;
          .....
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Title)
          &lt;/td&gt;
          .....
          &lt;td&gt;
              @if (item.Monitors == null || item.Monitors.Count == 0) 
                   {&lt;span&gt;No Monitors Assigned&lt;/span&gt;}
              else 
                   { string.Join(", ", item.Monitors.Select(m =&gt; string.Format("{0} {1}", m.FirstName, m.LastName))); }
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Resources)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
              @Html.ActionLink("Details", "Details", new { id=item.ID }) |
              @Html.ActionLink("Delete", "Delete", new { id=item.ID })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  &lt;/table&gt;
  </code></pre>
  
  <p>And here is the controller....</p>
  
  <pre><code>    public ActionResult Index()
      {
          var tasks = from t in db.Tasks where t.IsActive == true select t;
          return View(tasks);
      }
  </code></pre>
  
  <p>I would like for the list of Monitors and the list of Resources to display as a string on the Index, Delete and Details Views i.e. 'Monitor 1, Monitor 2, Monitor 3' and 'Resource 1, Resource 2, Resource 3'.</p>
  
  <p>However on the other views (Create and Edit), I want them to appear as a selectable list.</p>