I have a got database of vehicles. The database contains properties such as manufacturers, models, engine size and fueltype.
Now in my project(View) I am displaying this data in a table and using dropdowns to filter the table. At the moment i have got a manufacturer dropdown and a car model dropdown. when a user selects the dropdowns they click a search button that that filters the according to the drop downs. This is how my project is working at the moment.
Is there anyway i could filter the dropdowns? what i mean by this is that is there a way i could select the manufacturer dropdown and this then filters all car Models according to the slected manufacturer .. so instead of showing all the models just show the selected manufacturer dropdowns?
Controller
public ActionResult BrowseCars( string manufacturer, string model)
{
ViewBag.manufacturer = (from m in _carCatalogue.CarsTable
select m.Name).Distinct();
ViewBag.model = (from v in _carCatalogue.CarsTable
select v.Vehicle).Distinct();
var car = from t in _carCatalogue.CarsTable
orderby t.Name
where t.Name == manufacturer || manufacturer == null || manufacturer == ""
where t.Vehicle == model || model == null || model == ""
select t;
return PartialView("_BrowseCars", car);
}
View
@model IEnumerable
Use the relevant dropdowns below to find the vehicle
@using (Html.BeginForm())
{
}
Mnaufacturer | Model | Engine Size | BHP |
|---|---|---|---|
@Html.DisplayFor(modelItem => item.Name) | @Html.DisplayFor(modelItem => item.Vehicle) | @Html.DisplayFor(modelItem => item.EngineSize) | @Html.DisplayFor( modelItem => item.Bhp) |
Thank you for your time
Replies
Know the answer? Post it — somebody with the same question will find it here.