public async Task <IActionResult> Search(int id, [FromQuery] CocktailSearchViewModel vm) { var allIngredients = (await ingredientServices.GetAllDTOAsync()); vm.AllIngredients = new List <SelectListItem>(); vm.AllIngredients.Add(new SelectListItem("Select...", "")); allIngredients.ForEach(c => vm.AllIngredients.Add(new SelectListItem(c.Name, c.Id.ToString()))); if (string.IsNullOrEmpty(vm.NameKey) && vm.MinRating == null && vm.IngredientId == null) { return(View(vm)); } var searchParameters = new CocktailSearchDTO { NameKey = vm.NameKey, MinRating = vm.MinRating, IngredientId = vm.IngredientId }; vm.Paging.Count = await cocktailServices.SerchResultCountAsync(searchParameters); vm.Paging.ItemsPerPage = itemsPerPage; vm.Paging.CurrentPage = id == 0 ? 1 : id; vm.Result = (await cocktailServices.SearchAsync(searchParameters, itemsPerPage, vm.Paging.CurrentPage)) .Select(b => b.MapToViewModel()); return(View(vm)); }