你好我在控制器类中有这个lambda表达式,我想只采用模数
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());
视图
@model IEnumerable<Models.Modulos>
错误是:
传递到字典中的模型项的类型为'System.Collections.Generic.List
1[<>f__AnonymousType6
1 [Models.Modulos]]',但此字典需要类型为'System.Collections.Generic的模型项.IEnumerable`1 [Models.Modulos]'
任何人都可以帮助我?感谢
答案 0 :(得分:2)
看起来你用这一行不必要地创建了一个匿名类型:
.Select(s => new { s.Modulos.Modulos})
简单地尝试(应该返回IEnumerable<Modulos>
):
.Select(s => s.Modulos.Modulos)