我有数据库。实际上,我正在为它显示从我的数据库最新的10图像,但我想从数据库中显示随机10图像。我该怎么办?
public ActionResult Details(int id)
{
var products = db.TblProductImages.Include(t => t.TblProduct);
ViewData["viewcategory"] = (from p in products orderby p.ProductID descending select p).Take(10).ToList();
if (image == null)
{
return HttpNotFound();
}
return View(image);
}
答案 0 :(得分:4)
这样做:
(from p in products orderby Guid.NewGuid() select p).Take(10).ToList()