因为前面没有一类型 所以才会导致报错
换个思路想一下,我们可以自己定义个类
例子
var PostPingLun = (from PL in db.PostPingLun
join Yh in db.Usera on PL.UserId equals Yh.UserId
where PL.PostId == id
select new
{
PlNeiRong = PL.PostCommentsText, //评论内容
YhId = Yh.UserId, //用户Id
YhImg = Yh.UserImg, //用户头像
YhName = Yh.UserName //用户名
}).ToList();
List<PingLunAndUsera> PLUse = new List<PingLunAndUsera>();
foreach (var item in PostPingLun)
{
//实例化对象
PingLunAndUsera pu = new PingLunAndUsera();
pu.PlNeiRong = item.PlNeiRong;
pu.YhId = item.YhId;
pu.YhImg = item.YhImg;
pu.YhName = item.YhName;
PLUse.Add(pu);
}
ViewBag.PingLAndUsera = PLUse;