I have these two classes and I need a DropDownListFor with the information of the ModeloVeiculo
classes, and this DropDownListFor will be done in
create.cshtml of class Veiculo
, I believe the correct question would be, how to load information into a DropDownListFor, this information being of a foreign key!
public class Veiculo
{
public int ID { get; set; }
public string Tipo { get; set; }
public ModeloVeiculo ModeloVeiculo { get; set; }
}
public class ModeloVeiculo
{
public int ID { get; set; }
public string Descricao { get; set; }
}
View:
<div class="editor-field">
@Html.DropDownListFor(model => model.ModeloVeiculo,
new SelectList(Model.ModeloVeiculo, "ID", "Descricao"))
@Html.ValidationMessageFor(model => model.ModeloVeiculo)
</div>