public async Task OnGetAsync( string sortOrder, string make, string model, string min_price, string max_price, string min_budget, string max_budget, string mileage, string transmission, string fuel_type, string body_type, int?pageIndex ) { //Select Lists BodyTypes = await _context.StocklistImport .Select( s => new SelectListItem { Value = s.BodyType, Text = s.BodyType, Selected = s.BodyType == body_type } ) .Distinct() .ToListAsync(); Makes = await _context.StocklistImport .Select( s => new SelectListItem { Value = s.Make, Text = s.Make, Selected = s.Make == make } ) .Distinct() .ToListAsync(); ModelMakes = await _context.StocklistImport .Select( s => new SelectListGroup { Name = s.Make } ) .Distinct() .ToListAsync(); Models = (await _context.StocklistImport .ToListAsync()) .GroupBy(grp => new { grp.Make, grp.Model, grp.BodyType }) .Select( s => new SelectListItem { Value = s.Key.Model, Text = s.Key.Model + " (" + s.Key.BodyType + ")", Group = ModelMakes.SingleOrDefault(m => m.Name == s.Key.Make) } ) .OrderBy(s => s.Group.Name) .ThenBy(s => s.Text) .ToList(); MinPrice = NumberFunctions.CurrencyToInt(min_price); MaxPrice = NumberFunctions.CurrencyToInt(max_price); MinBudget = NumberFunctions.CurrencyToInt(min_budget); MaxBudget = NumberFunctions.CurrencyToInt(max_budget); //Add a default sort order if (sortOrder == null) { sortOrder = "Recent"; } CurrentSortID = sortOrder; }