MVC3+EF4.1+Linq探讨之select new问题
select new后 页面要怎么接收这些属性呢
貌似用对象接收会报转型错误
代码:
控制器:
var user = from c in db.User
where c.bOnLine
&& c.IsAndroid != 1
select new
{
c.UserID,
c.Accounts,
c.Point,
c.SavePoint,
c.LoginServerID
};
return View(user.ToList());
页面
@foreach (MVC3.Models.UserAccounts item in Model)
{
<td>@item.UserID
</td>
<td>@item.Accounts
</td>
<td>@item.Point
</td>
<td>@item.SavePoint
</td>
<td>@item.LoginServerID
</td>
}
[解决办法]
匿名对象不能作为返回类型,你需要返回指定对象的LIST
即: select new 是不行的
要换成 select new YourClass {}