Add drop down list filter to search action
User Generated
xvzoreyrl
Programming
Description
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);
}
This question has not been answered.
Create a free account to get help with this and any other question!
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
East of Eden
by John Steinback
Divergent
by Veronica Roth
Pachinko
by Min Jin Lee
Enders Game
by E. M. Forster
Orphan Train
by Christina Baker Kline
The Nightingale
by Kristin Hannah
The Secret Life of Bees
by Sue Monk Kidd
The Eyes Were Watching God
by Zora Neale Hurston
The Glass Palace
by Amitav Ghosh