I have a Registry entity that has a Teacher , the Teacher has a Record list. How can I create a foreach in the Details view of the Registry to list the Professor name that belongs to the record in question?
Controller registry:
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
RegistroCompleto registroCompleto = db.RegistrosCompletos.Find(id);
if (registroCompleto == null)
{
return HttpNotFound();
}
return View(registroCompleto);
}
Record details view:
@model Meu.Projeto.Registro
<div>
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Professor.Nome)
</dt>
<dd>
@Html.DisplayFor(model => model.Professor.Nome)
</dd>
</dl>
</div>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.IdRegistroCompleto })
@Html.ActionLink("Back to List", "Index")
</p>
Registration Class:
public class Registro : RepositorioBase<Registro>
{
[Key]
[Display(Name = "Número do registro")]
public int IdRegistroCompleto { get; set; }
public Professor Professor { get; set; }
[Display(Name = "Data de cadastro")]
public DateTime DataCadastro { get; set; }
public int IdProfessor { get; set; }
}
Teacher class:
public class Professor : RepositorioBase<Professor>, IProfessor
{
[Key]
public int IdProfessor { get; set; }
public List<RegistroCompleto> RegistrosCompletos { get; set; }
}