Tôi muốn hiển thị dữ liệu trong chế độ xem lưới bằng cách sử dụng 3 bảng trong cơ sở dữ liệu SQL.Hiển thị dữ liệu từ cơ sở dữ liệu SQL trong GridView
đầu tiên tôi tạo mẫu
public class common
{
public Artist Artist { get; set; }
public Album Album { get; set; }
public Genre Genre { get; set; }
}
Sau đó Đây là Controller
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());
}
}
Sau rằng đây là quan điểm của tôi
@model IEnumerable<test1.Models.common>
@{
ViewBag.Title = "Show1";
}
<h2>Show1</h2>
<div>
@{
var grid = new WebGrid(Model, defaultSort:"Name");
}
@grid.GetHtml()
</div>
Nhưng nó không hiển thị bất kỳ dữ liệu? Tôi có thể làm như thế nào?
tôi nghĩ bạn đã bỏ lỡ câu hỏi ... AKA phần WebGrid – Seabizkit