Hi all,
I'm using a pagination method for displaying search results returned from my database. I'm creating an Html.ActionLink for each extra page, and what I'm wondering is, how do you put the string that was searched into the ActionLink? Below is part of my partial view that I'm populating a div with. It comes after the results so the user can select another page of results.
<% if (Model.HasNextPage)
{ %>
<% for (var i = 1; i < Model.TotalPages; i++)
{ %>
<%= Html.ActionLink(i.ToString(), "MyPartialPage", "MyController", new { searchString = Cache[searchString], page = i }, new { @id = "SearchResults" })%>
<% } %>
<% } %>
MyController looks like:
public ActionResult SearchResults(string searchString, int? page)
{
var theResults = driverRepository.GetResults();
var searchResults = drivers.Where(q => q.Filename.Contains(searchString));
var paginatedDrivers = new PaginatedList<Driver>(searchResults, page ?? 0, pageSize);
return View("SearchResults", paginatedDrivers);
}
There is a textbox and button. The user types the search and presses the button which fires some javascript that gets the text from the textbox and posts to SearchResults accordingly.
I want to keep what they searched so when I build my ActionLinks, the search parameter is still present.