title: Get data from two tables(join) with linq and return result into view
body: <p>I have two tables: Projects and ProjectsData and I want to execute query with join and get the result in the View.</p>
  
  <p>In the Controller I have this code:</p>
  
  <pre><code>ViewBag.projectsData = (from pd in db.ProjectsData
                                     join p in db.Projects on pd.ProjectId equals p.ID
                                     where pd.UserName == this.HttpContext.User.Identity.Name 
                                     orderby p.Name, p.ProjectNo
                                     select new { ProjectData = pd, Project = p });
  </code></pre>
  
  <p>What I should use in the View to extract this data. I tried that:</p>
  
  <pre><code>@foreach (var item in ViewBag.projectsData)
  {
      @item.pd.UserName
  }
  </code></pre>
  
  <p>but it doesn't work...</p>