1
I have the model (superclass) Pessoa
and the model Aluno
public partial class Pessoa
{
public Pessoa()
{
this.Escola = new HashSet<Escola>();
}
[Key]
public int PessoaID { get; set; }
public String Nome { get; set; }
public String Morada { get; set; }
public virtual ICollection<Escola> Escola { get; set; }
}
public partial class Aluno
{
public Aluno()
[Key, ForeignKey("Pessoa")]
public int AlunoID { get; set; }
public String NomeEscola { get; set; }
public String AnoEscolar { get; set; }
public String TurmaEscolar { get; set; }
public virtual Pessoa Pessoa { get; set; }
}
I intend to make a selectlist of the Name attribute in a view where Alunoid is equal to Pessoaid I tried with the following code on the Student’s controller but without success
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Aluno aluno = db.aluno.Find(id);
if (aluno == null)
{
return HttpNotFound();
}
ViewBag.AlunoID = new SelectList(db.Pessoa, "PessoaID", "Nome", aluno.AlunoID);
return View(aluno);
}
Let me get this straight. You want to take your
contexto
, all objects that have the propertyPessoaID
equal toaluno.AlunoID
?– Jéf Bueno
Yes, it was intended to obtain the names of the Person table that corresponded to the ID of the Student table, in which these names would be sent to a Listbox. I’ve already created a Viewmodel that I think is necessary...
– WickedOne