Error sending data to View

0

Inquiry to bring users in.

public IEnumerable PopulaTabelaUsuario()
{
     var banco = new DbBancoContext();
     var listaUsuarios = (from l in banco.USUARIOS_PROCESSO 
         select new{ l.ID_USUARIO, l.NOME_USUARIO }).ToList();
     return  listaUsuarios;
} 

My controller.

public ActionResult AreaPrincipal()
{
    var lista = new ConsultasNecessarias();
    var usuarios = lista.PopulaTabelaUsuario();
    //var r = new DbBancoContext();
    //var s = r.USUARIOS_PROCESSO.Select(m=>m.NOME_USUARIO).ToList();
    return View(usuarios);           
}

My View.

@model IEnumerable<ControleVisita.Models.USUARIOS_PROCESSO>    
@{
    ViewBag.Title = "Área Principal";        
}

@section Menu{        
}
<table class="table table-hover">
    <thead>
        <tr>
            <th>Id Usuário</th>
            <th>Nome</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(modelItem => @item.ID_USUARIO)</td>
                <td>@Html.DisplayFor(modelItem => @item.NOME_USUARIO)</td>
            </tr>          
        }
    </tbody>
</table>

But when I run it displays the following error.

  

The template item entered in the dictionary is from   type System.Collections.Generic.List 1[<>f__AnonymousType4 2 [System.Int32, System.String]] ',   but this dictionary requires an item of type   'System.Collections.Generic.IEnumerable'1 [ControlVisit.Models.USER_PROCESSUS]'.

    
asked by anonymous 15.10.2014 / 17:56

1 answer

1

Using select new , a new object of type anonymous will be created as a result of the query.

You can not return an anonymous IEnumerable ( IEnumerable<AnonymousType> ) because the type to be returned is not known.

Try to modify your QueryUserPhone () method to return IEnumerable<USUARIOS_PROCESSO> .

public IEnumerable<USUARIOS_PROCESSO> PopulaTabelaUsuario()
{
    var banco = new DbBancoContext();
    IEnumerable<USUARIOS_PROCESSO> listaUsuarios = (
        from l in banco.USUARIOS_PROCESSO
        select new USUARIOS_PROCESSO { l.ID_USUARIO, l.NOME_USUARIO }
    ).ToList();
    return  listaUsuarios;        
}
    
15.10.2014 / 18:49