0
I have an orderly list, which I need to display only the first 5 items, not all bank records, so I’m not getting it. Here’s my code as is:
public class DashboardController : Controller
{
private NFeWebContext db = new NFeWebContext();
// GET: Dashboard
public ActionResult Index()
{
var dashboard = new DashboardViewModel();
var lista = new List<NotaFiscal>();
var participantes = db.Participantes
.ToList();
var notas = db.NotasFiscais
.ToList();
foreach (var part in participantes)
{
var x = new NotaFiscal();
var res = notas.Where(y => y.ClienteID == part.ParticipanteId).Sum(o => o.ValorTotalNota);
x.ClienteID = part.ParticipanteId;
x.ValorTotalNota = res;
x.NomeCliente = part.NomeParticipante;
lista.Add(x);
}
dashboard.NotasFiscais = lista.OrderByDescending(x => x.ValorTotalNota).ToList();
for (var i= 0; i < 4; i++)
{
lista.ToList();
}
return View(dashboard);
}
}
Possible duplicate of How to sort and list only 5 items from a list?
– Barbetta
the context is the same but the doubt is different!
– WPfan
is written "Possible", if it is duplicated your question is closed, if it is not, nothing happens ;)
– Barbetta