I'm having an error while passing the contents of the controller to the view, I'm doing this way, the ViewBag is being populated with the data.
In my application I select the items:
public List<TB_EMPRESA> ListarTodos()
{
var strQuery = "select * from tb_empresa";
using (contexto = new Contexto())
{
var retornoDataReader = contexto.ExecutaComandoComRetorno(strQuery);
return TransformaReaderEmListaObjetos(retornoDataReader);
}
}
no controller:
// GET: CadastroUsuario
public ActionResult Index()
{
//lista empresa
var tbuscarEmpresa = new EmpresaAplicacao();
var listarEmpresa = tbuscarEmpresa.ListarTodos();
ViewBag.Empresa = listarEmpresa;
return View();
}
in View
<div class="col-md-3 form-group">
@Html.LabelFor(x => x.tbidempresa)
@Html.DropDownListFor(x => x.tbidempresa.IDEMPRESA, ViewBag.Empresa as SelectList, "Selecione um item..", new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.tbidempresa)
</div>