0
I have one question
I have 1 User class and composed by 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 doubt is in my controller to popular my Dropdownlistfor
My DAO Classes 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 looked in some forums I found nothing using composition I would like to do how to popular the dropdown coming from the bank and also do cascading in the course, I only found with Javascript but I can not use because it also does not recognize the composition of other classes
It wouldn’t just be;
@Html.DropDownListFor(model => model.Sexo ...
– Leandro Angelo