Reputation: 520
I have a routing question that i have been tinkering with but have been unsuccessful in trying to get it to work.
Basically, i have the default route in my global.asax file and i have the following controller with the following actions:
Controller = People Actions = Index & Search
When you visit the People page you get a search box, when you run a search, the form GETS to:
http://mysite/people/search?filter=a&searchType=IdentityCode&searchOption=StartsWith
What i would like to do is, drop the search in the url, so it will look something like this:
http://mysite/people?filter=a&searchtype=IdentityCode&searchOption=StartsWith
But still run the search action.
Is this at all possible?
Upvotes: 0
Views: 353
Reputation: 1621
You could do it by making index and search the same method.
public ActionResult Index(string filter, string searchType, string searchOption)
{
IList<Person> people;
if (String.IsNullOrEmpty(filter)) {
people = peopleRepo.GetAll(); // Get all the people, or none - whatever you prefer on the index page
}
else
{
people = peopleRepo.Search(filter, searchType, searchOption);
}
Return View("index", people);
}
Obviously I have taken license interpreting your code, but I hope you get the idea.
Upvotes: 1