okay so I have a teams table with TeamID, TeamName
and a games table with columns gameid, team1, team2
.
Now I dont have team1 and team2 as Foreign keys to the teams table. I understand this will make it easier but I want to learn without doing that. So team1
, and team2
are int fields. There is no constraint check.
So when I display it in my view, it displays the team1 and team2 columns but instead of displaying the integer ID, I want it to pull the team name from the teams table.
okay in my view I have the following:
@model IEnumerable<Betting.Models.Bets>
@{
ViewBag.Title = "List of Games";
}
@{
var grid = new WebGrid(source: Model, defaultSort: "EndDate", rowsPerPage: 3);
}
<h2>
Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<h2>
Betting List</h2>
<div id="grid">
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("Subject"),
grid.Column("Team1"),
grid.Column("Team2")
)
)
</div>
And my controller is really simple:
public ViewResult Index()
{
return View(db.Bets.ToList());
}