I have a MVC web application with multiple selects that allow multiple selections that the user can use to filter data. For example: A car database where the user can select by make, color and body style. A possible search would be (Red OR Blue) AND (Chevy OR Ford) AND (SUV). I have all the selects returned in my viewmodel as array of strings and all gets returned to my controller correctly. I have the Color array with 'Red' and 'Blue', the Model array with 'Chevy' and 'Ford' and the BodyStyle array with 'SUV'. Now that I have the model posted to the controller, how do I construct the linq statement that will allow and of these criteria to me blank or contain multiple selections?
Model:
public class SearchViewModel
{
public string[] Model { get; set; }
public string[] Color { get; set; }
public string[] Body { get; set; }
}
Controller:
public ActionResult Search(SearchViewModel search)
{
//TODO: Create linq for all search criteria
List<Cars> cars = db.Cars.Where(car => car.Model == search.Model[0]);
return View(cars);
}