Hi
This should be pretty easy, but I'm struggling to think of the best way to implement a simple search form. I have a form with several fields in (such as textboxes, select lists, etc.). When the page first loads I need it to populate the select lists with records from a database and set some default values for a couple of textboxes. Then they click a search button and it displays a table of results. All very standard.
The problem is that because I'm using an HTTP GET to perform the search, I have to handle everything in one action method, and need to prevent the search from running when the page first loads. One way I was thinking of was:
public ViewResult Search(SearchViewModel viewModel)
{
if (Request.Form["submitbutton"] != null) {
SearchViewModel model = _searchService.GetSearch(viewModel);
return View(model);
}
return View();
}
But that feels wrong for some reason (especially passing a view model to get back another view model), plus I still need to populate parts of the view model for the select lists if the page is loading for the first time.
Maybe I'm over complicating things, but can anyone give me some guidance?
Thanks
View Complete Post