Bring only certain amounts of information from the MVC database [closed]

0

I need to bring only 6 records of the database to display in View, instead of just 6 records, it's all coming up.

The code is as follows:

public PartialViewResult Cursos()
{
    ViewBag.Cursos = new CursoRepositorio().BuscarTodos().Take(6).ToArray();
    return PartialView();
}
    
asked by anonymous 03.03.2017 / 15:53

1 answer

1

In your Entity Framework query you need to enter how many records will be listed ...

Try to create an object

DaoCurso

And use a list of this course

List<DaoCurso> curso = null;

curso = entity.TBCURSO.Select(x=> new DaoCurso() { idcurso =x.idcurso , nomecurso = x.nomecurso ).Take(6).ToList();

And add that to your ViewBag;

ViewBag.Cursos = curso;
    
03.03.2017 / 16:21