title: How to print data of join query which are stored in Viewbag in ASP.NET MVC with Entity Framework?
body: <p>I want to display data from 2 different tables which are stored in <code>ViewBag</code> at view side but I'm unable to print the data, I get an error</p>
  
  <blockquote>
    <p>'object' does not contain a definition for 'Name'</p>
  </blockquote>
  
  <p>The code at controller side</p>
  
  <pre><code>public ActionResult Packages()
  {
      int Prov_id = 1;
  
      using (var db = new DataContex())
      {
          ViewBag.pack = db.Packages.Where(x =&gt; x.ProviderId == Prov_id).ToList();
  
          ViewBag.service = db.GroupServices.Join(db.PackageServices,
                  gs =&gt; gs.ServiceId,
                  ps =&gt; ps.ServiceId,
                  (gs, ps) =&gt; new
                  {
                      name = gs.ServiceName
                  })
                  .ToList();
  
      return View();
  }
  </code></pre>
  
  <p>View markup:</p>
  
  <pre><code>@foreach (var item in ViewBag.pack)
  {
      &lt;div class="col-md-6 bg-white mt-3"&gt;
          &lt;div class="card border package-grid p-3"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-8"&gt;
                      &lt;input type="hidden" /&gt;
                      &lt;h4 class="font-weight-bold py-2"&gt;@item.PackageName&lt;/h4&gt;
                      @foreach (var item1 in ViewBag.service)
                      {
                          &lt;h6 class="py-1"&gt;@item1.Name&lt;/h6&gt;
                      }
                      &lt;p class="py-3"&gt;@item.PackageDescription&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-12 mt-3 d-flex justify-content-between flex-wrap"&gt;
                      &lt;p&gt;&lt;strike&gt; Rs. @item.PackagePrice&lt;/strike&gt; &lt;span&gt;Rs. @item.PackageOfferPrice&lt;/span&gt; &lt;/p&gt;
                      &lt;span&gt;&lt;a href="#" class="btn btn-sm btn-outline-danger"&gt;Remove&lt;/a&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>