I’m just learning how to use .net and mvc4 and I have a problem. I have no idea how to show only the first 5(or any number) rows in a table. This is how I’m currently sending my information to the view.
public ActionResult ActiveCampaigns()
{
var campaigns = db.ActiveCampaigns.ToList();
return View(campaigns);
}
Thanks 🙂
Update:
Thanks for the quick responses! So simple!
db.ActiveCampaigns.Take(5).ToList()
I searched high and low and couldn’t find this, my google-fu must be off. Thanks again!
The basic approach would be
But depending on what type of Context
dbis, this might fail.Skip()andTake()are not always available or allowed on all IEnumrable-derived interfaces. In that case read the error. Usually you can fix it in two ways:or, when you have a convenient sort-criterium: