Creating DropDownListFor with typed view

0

Good afternoon guys,

I'm starting my studies in the art of ASP.NET C #. I'm having trouble creating a DropDownListFor.

How I'm doing:
 - I'm using ADO.NET
 - I have my model Equipment
 - I have a Viewmodel EquipmentCompany, just to list all the companies (id and description).
 - in my Hardware controller, in the Insert action, I create the following:

  ViewBag.ListaEmpresa = new SelectList(
                                        new EmpresaDAO().ListaEmpresaDropDown().ToList(),
                                                   "EmpresaId",
                                                   "CodEmpresa"
                                                );


 - These are some of the ways I tried to create the ddl, but without success:

@model Objects.ValueObjects.EquipamentoVO

@Html.DropDownListFor(m => m.EmpresaId, new SelectList((ViewBag.ListaEmpresa) as SelectList, "EmpresaId", "CodEmpresa"), "Selecione uma empresa")
@Html.DropDownListFor(m => m.EmpresaId, new SelectList(ViewBag.ListaEmpresa, "EmpresaId", "CodEmpresa"), "Selecione uma empresa")
@Html.DropDownListFor(m => m.EmpresaId, new SelectList(@ViewBag.ListaEmpresa,"ListaEmpresa", "CodEmpresa"), "Selecione uma empresa")
<br>

Would anyone know where I'm going wrong? or give me an idea how to create a ddl with a typed view?

    
asked by anonymous 11.07.2017 / 21:49

0 answers