我有数据库。其实,我正在为它从我的数据库显示最新的10个图像,但我想从数据库中显示随机10图像。我该怎么做?从mvc4中的数据库中选择随机数据C#
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);
}
为什么你就不能在现有的指数范围内产生10张随机数(0 - >块长度)? http://stackoverflow.com/questions/2706500/how-do-i-generate-a-random-int-number-in-c – bill