public ActionResult GetAllRestaurantsFromCity(int id) { var cityidlist = RestaurantManager.GetCitiesId(); bool validCityId = false; //if the city code is not in the database or not correct, it display a the index error view foreach (int index in cityidlist) { if (id == index) { validCityId = true; } } if (validCityId == true) { var restaurantlist = RestaurantManager.GetRestaurantsFromCity(id); return(View(restaurantlist)); } else { return(RedirectToAction(nameof(IndexError))); } }