title: C# MVC ViewBag error
body: <p>I'm new to C# MVC so please be patient.  I'm having some trouble displaying output for the ViewBag.  The application is a Fantasy Football webpage so I have three tables (right now, more to come) one for the basic player info (dbo.Player), one for player background (dbo.PlayerBackground), and one is just a definition table for the team (dbo.Team).</p>
  
  <p>In one of my pages I have a name search and search by position and want to return information across these three tables.  </p>
  
  <pre><code>public ActionResult Index()
  {
      var players = (from p in db.Players
                     join pb in db.PlayerBackgrounds on p.playerId equals pb.playerID
                     join t in db.Teams on p.teamAbbre equals t.teamAbbre
                     select new { playerID = p.playerId, playerName = p.name, position = p.position,
                                  height = pb.height, weight = pb.weight, college = pb.college, dob = pb.dob,
                                  imageUrl = pb.imageUrl, years = pb.years,
                                  teamName = t.name
                                  }).ToList();
  
      ViewBag.data = players;
      return View();
  }
  </code></pre>
  
  <p>The query works fine but in index.cshtml I keep getting errors.</p>
  
  <pre><code>@foreach (var player in ViewBag.data)
  {
      &lt;tr class="success ui-dragable playerRow"  style="display: none;"&gt;
          &lt;td&gt;
              &lt;input type="checkbox" /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink( (string)player.playerName, "Details", new { id = player.playerID }, new { @class = "detailsLink" })
          &lt;/td&gt;
          &lt;td&gt;
              @player.teamName
          &lt;/td&gt;
          &lt;td&gt;
              @player.position
          &lt;/td&gt;....
  </code></pre>
  
  <p>From the research I've done, this seems like it should work.  I've tried it both with and without the (string) cast.  Without the cast it gives me red squiggly saying I should cast and when I do I get: </p>
  
  <blockquote>
    <p>Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'playerName'</p>
  </blockquote>
  
  <p>As I step through, I can watch player and it has the various properties just as it should.  Any idea what I'm doing wrong?</p>