I need to join two tables in my controller and pass the result to my view. Trouble is, I cannot seem to be able to access the column values from the joined table once I'm in the view.
I've tried to do a join in my controller, but I have a feeling I'm going in the wrong direction.
Controller:
//GET: kurser/stats/5
public ActionResult Stats()
{
var stat = from k in db.kursister
join ku in db.kurser
on k.kursus_id equals ku.kursus_id
select k;
return View(stat);
}
My view:
@model IEnumerable<Itucation.Models.kursister>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div>
@{
foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.kursus_navn)<br/>
}
}
</div>
I would expect to be able to get the value of kursus_navn, which is in the kursus table, which is what I'm trying to join with the kursister table. But it doesn't work.
kobject. Currently you'll get all kursister records that have a matching kursus_id in kurser, but no data from the kurser table.kand you can access only property ofkursistermodel, so you can not accesskurserbecause you have not select this property