我想使用 SQL 数据库中的 3 个表在网格视图中显示数据。
首先我创建了模型
public class common
{
public Artist Artist { get; set; }
public Album Album { get; set; }
public Genre Genre { get; set; }
}
然后这是控制器
public ActionResult Show1()
{
var query = from a in DB.Album
join b in DB.Artists
on a.ArtistId equals b.ArtistId
join c in DB.Genre
on a.GenreId equals c.GenreId
where (b.ArtistId == 2)
select new common { Album = a, Artist = b, Genre = c };
return View(query.ToList());
}
}
之后这是我的观点
@model IEnumerable<test1.Models.common>
@{
ViewBag.Title = "Show1";
}
<h2>Show1</h2>
<div>
@{
var grid = new WebGrid(Model, defaultSort:"Name");
}
@grid.GetHtml()
</div>
但它没有显示任何数据?我该怎么做?