Two parameters in asp.net mvc route
- by olst
Hi.
This is a modification to a question I've asked before on this forum.
My controller action:
public ActionResult SearchResults(string searchTerm, int page)...
My view:
<%= Html.PageLinks((int)ViewData["CurrentPage"], (int)ViewData["TotalPages"], i => Url.Action("SearchResults", new { page = i }))%>...
The route entries:
routes.MapRoute(
null,
"SearchResults",
new { controller = "Search", action = "SearchResults", page = 1 } // Defaults
);
routes.MapRoute(
"Search",
"SearchResults/Page{page}",
new { controller = "Search", action = "SearchResults" },
new { page = @"\d+" }
);
My goal is to have paging links for the search results. The problem is that when I click any page in the paging links, it gives me the search results of an empty serach term.
How can I pass the search term parameter which is a string in addition to the page number parameter ?
What should I put in the routing ?