I have an Index
view that should display the name of each person's course, however, in the model used there is only the Course Id
, the course name is in another model - CursosModel
- and in another table in the database. How can I display the course name in my view?
Index view:
@model IEnumerable<FeedbackUnivicosa.Models.Professor>
@{
ViewData["Title"] = "Professores";
}
<h4>@ViewData["Title"]</h4>
<form asp-action="Index" method="get">
<div >
<p>
<input type="text" name="SearchString" value="@ViewData["CurrentFilter"]" />
<button type="submit" ></button>
<a asp-action="Index"><i ></i></a>
<a asp-action="Create" >Cadastrar</a>
</p>
</div>
</form>
<table >
<thead>
<tr>
<th></th>
<th>
<a asp-action="Index" asp-route-sortOrder="@ViewData["NameSortParm"]">Professor</a>
</th>
<th>
<a asp-action="Index" asp-route-sortOrder="@ViewData["EmailSortParm"]">Email</a>
</th>
<th>
<a asp-action="Index" asp-route-sortOrder="@ViewData["CursoSortParm"]">Curso</a>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td >
<a asp-action="Edit" asp-route-id="@item.Id"><i ></i></a>
<a asp-action="Delete" asp-route-id="@item.Id"><i ></i></a>
</td>
<td>
@Html.DisplayFor(modelItem => item.Nome)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailProfessor)
</td>
<td>
@Html.DisplayFor(modelItem => item.CursoId)
</td>
</tr>
}
</tbody>
</table>
I am trying to show the course name on the Index
view.
CodePudding user response:
because the Microsoft website teaches Add the model
so after you can reference the Microsoft site.