Home > Software engineering >  Order a list on page by LastName in the controller
Order a list on page by LastName in the controller

Time:06-27

I'm new to C# and I am trying to figure out how to Order the candidate list on the candidates index page by LastName in the Candidates controlle, here is the code:

    // GET: Candidates
    public async Task<IActionResult> Index()
    {
        var applicationDbContext = _context.Candidate.Include(c => c.Job);
        return View(await applicationDbContext.ToListAsync());
    }

CodePudding user response:

Try:

var applicationDbContext = _context.Candidate.Include(c => c.Job).OrderBy(l => l.LastName);
  • Related