1
I have an entity Registering who owns a Professor, the Professor has a list of Registering. How can I create a foreach in View details of Registering to list the name of Professor which belongs to the register in question ?
Registry controller:
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);
}
View log 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; }
}
Put the classes involved?
– novic
Acebei to amend the Code
– Morais
RegistroCompleto
missed that ???– novic
The class name was wrong, now it’s right
– Morais