I have a following doubt
I have 1 User class and it consists of other classes Gender, Course and Semester
Ex
public int Id { get; set; }
public string Nome { get; set; }
public Genero Sexo { get; set; } = new Genero();
public Curso Curso { get; set; } = new Curso();
public Semestre Semestre { get; set; } = new Semestre();
And my question is in my controller to popular my DropDownListFor
My DAO Courses Equal to Course and Semester
public List<Genero> ListarGenero()
{
var Genero = new List<Genero>();
SqlDataReader reader;
using (contexto = new Contexto())
{
var strQuery = " SELECT * FROM Genero ";
reader = contexto.ExecutaComandoComRetorno(strQuery);
while (reader.Read())
{
var temObjeto = new Genero()
{
id = int.Parse(reader["Id"].ToString()),
Sexo = reader["Genero"].ToString()
};
Genero.Add(temObjeto);
}
}
reader.Close();
return Genero;
}
My Action
public ActionResult GetGenero()
{
GeneroDAO gen = new GeneroDAO();
ViewBag.Genero = new SelectList(gen.ListGenero(), "Id", "Sexo");
return View();
}
View
@Html.DropDownListFor(model => model.Sexo.id, (SelectList)ViewBag.Genero, new { @class = "form-control" })
I searched on some forums and found nothing using composition I would like to make dropdowns popular from the bank and also cascade in the course, I just found JavaScript but I can not use it because it does not recognize the composition of the other classes.