我有數據庫。其實,我正在爲它從我的數據庫顯示最新的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