The following actions in a controller get the search person page and return the search person results. At the moment, I have one drop down list filter for the country of birth, one drop down list filter for city and two other search filters by “age” and “gender”. I want to add an additional drop down list filter which will allow me to search by hair colour. I am a little bit inexperienced in this area and need some help to be able to do this.
/// <summary>
/// Gets the person search page.
/// </summary>
/// <returns>
/// The person search page.
/// </returns>
/// GET: /Person/Search
[HttpGet]
public ActionResult Search()
{
return
this.View(
new PersonSearchViewModel
{
CountryViewModel =
new CountryViewModel
{
Country =
new SelectList(this.countryManager.GetCountries(), “Name”),
Cities = new SelectList(new List<City>(), “Name”)
}
});
}
/// <summary>
/// Searches the person.
/// </summary>
/// <param name=”viewModel”>
/// The <see cref=”PersonSearchViewModel”/> to filter by.
/// </param>
/// <returns>
/// The <see cref=”ActionResult”/>.
/// </returns>
/// POST: /Person/Search
[HttpPost]
public ActionResult Search(PersonSearchViewModel viewModel)
{
viewModel.CountryViewModel = new CountryViewModel
{
Countries = new SelectList(this.countryManager.GetPCountries(), “Id”, “Name”),
Cities =
viewModel.SearchCriteria.CountryId > 0
? new SelectList(
this.countryManager.GetCitiesviewModel.SearchCriteria.CountryId.GetValueOrDefault()),
“Id”,
“Name”)
: new SelectList(new List<City>(), “Id”, “Name”)
};
viewModel.PersonViewModel = new PersonViewModel
{
People = new SelectList(this.personManager.GetAllPeople)),
};
if (!this.ModelState.IsValid)
{
return this.View(viewModel);
}
viewModel.SearchResult = this.peopleManager.FindPeople(viewModel.SearchCriteria, 1234);
return this.View(viewModel);
}


0 comments