1

Hello I have this lambda expression in controller class, and i want to take only modulos to

return PartialView( db.AcessosUsuarios               
           .Join(db.Perfils,
           Au => Au.IdPerfil,
           p => p.IdMenu,
           (Au, p) => new { AcessosUsuarios = Au, Perfils = p })
           .Where(x => x.AcessosUsuarios.IdUsuario == Usu)
           .Join(db.Menus,
           p => p.Perfils.IdPerfil,
           Me => Me.IdMenu,
           (Me, p) => new { Menus = Me, Perfils = p })
           .Join(db.Modulos,
           Me => Me.Menus.Perfils.IdMenu,
           Mo => Mo.IdModulo,
           (Me, Mo) => new { Modulos = Mo, Menus = Me, Me.Menus.Perfils.IdMenu })
           .OrderByDescending(Mod => Mod.Modulos.Ordem)
           .Join(db.AcessosAssinantes,
           Mo => Mo.Modulos.IdModulo,
           Aa => Aa.IdModulo,
           (Mo, Aa) => new { Modulos = Mo, AcessosAssinantes = Aa })
           .Where(y => y.AcessosAssinantes.IdAssinante == Ass)
           .Select(s => new { s.Modulos.Modulos})
           .ToList().AsEnumerable());

the view

@model IEnumerable<Models.Modulos>

the error is :

The model item passed into the dictionary is of type 'System.Collections.Generic.List1[<>f__AnonymousType61[Models.Modulos]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Models.Modulos]'

Anyone can help me?? Thanks

1 Answer 1

2

It looks like you've created an anonymous type needlessly with this line:

.Select(s => new { s.Modulos.Modulos})

Try instead simply (should return an IEnumerable<Modulos>):

.Select(s => s.Modulos.Modulos)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I have another question...The OrderBy is not working, you know why??
@Kate I'm not sure, but maybe it's because you do a join after the order? You probably want to apply the OrderBy last.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.