请教一个asp.net mvc的问题
我用的是asp.net mvc4+ef5.0做的,现在有这么一个问题,我用ef查询部分字段的值,但是在视图里面获取字段的值老是提示没定义,找了很久也没有找到原因,望求大家帮忙解决一下。
action代码如下:
public ActionResult Index()
{
using (SCEntities sc = new SCEntities())
{
//s => new { s.title, s.adddate, s.ContentSort.MenuName }为查询指定字段的值
var list = sc.Contents.Include("ContentSort").OrderByDescending(p => p.adddate).Select(s => new { s.title, s.adddate, s.ContentSort.MenuName }).ToList();
ViewBag.list = list;
}
return View();
}
视图代码如下:
@foreach (var list in ViewBag.list)
{
<tr>
<td width="300" height="25">@list.title</td>
<td width="150" height="25" align="center">@list.MenuName</td>
<td width="150" height="25" align="center">@list.adddate</td>
</tr>
}