Ok, so I have a Course entity which has a many to one or zero relationship with the Industry entity. This means that a course can have a industry specified or not, for classification purposes. I created all entities and models through EF, so the only link stored in the Course entity is IndustryId.
The default views created upon creating the Controller displays the IndustryId.
What I'm trying to do now is to display the Description instead, which is a property of the Industry entity. Here is my code:
@foreach (var item in Model)
{
<tr>
<td><a href="@Url.Action("Details","Course", new { id=item.Id })"><img class="media-object" data-src="holder.js/64x64" /></a></td>
<td>@Html.DisplayFor(modelItem => item.Name)</td>
<td>@Html.DisplayFor(modelItem => item.Description)</td>
<td>@Html.DisplayFor(modelItem => item.Industry.Description)</td>
<td>@Html.DisplayFor(modelItem => item.Author)</td>
<td>
<a href="@Url.Action("Edit","Course", new { id=item.Id })"><i class="icon-edit"></i> Modify</a>
<a href="@Url.Action("Delete","Course", new { id=item.Id })"><i class="icon-trash"></i> Delete</a>
</td>
</tr>
}
Problem now is that the line @Html.DisplayFor(modelItem => item.Industry.Description displays nothing. Does anyone know why?