title: error while trying to display view in asp.net mvc 3 app?
body: <p>I am trying to display a list in a View, how to fix this error?</p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type
    'System.Data.Objects.ObjectQuery<code>1[System.Linq.IGrouping</code>2[System.Int32,mvc3Post.Models.Contact]]',
    but this dictionary requires a model item of type
    'System.Collections.Generic.IEnumerable`1[mvc3Post.Models.Contact]'.</p>
  </blockquote>
  
  <p>controller:        </p>
  
  <pre><code>    public ActionResult Index()
      {
          AdventureWorksEntities db = new AdventureWorksEntities();
  
          var result = from soh in db.SalesOrderHeaders
                       join co in db.Contacts
                       on soh.ContactID equals co.ContactID
                       orderby co.FirstName
                       group co by co.ContactID into g
                       select g;
          return View(result.AsEnumerable());
      }
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>@model IEnumerable&lt;mvc3Post.Models.Contact&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;
              NameStyle
          &lt;/th&gt;
          &lt;th&gt;
              Title
          &lt;/th&gt;
      &lt;/tr&gt;
      @foreach (var item in Model)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.NameStyle)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Title)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.ActionLink("Edit", "Edit", new { id = item.ContactID }) |
                  @Html.ActionLink("Details", "Details", new { id = item.ContactID }) |
                  @Html.ActionLink("Delete", "Delete", new { id = item.ContactID })
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>