Two parameters in asp.net mvc route

Posted by olst on Stack Overflow See other posts from Stack Overflow or by olst
Published on 2010-04-22T18:43:11Z Indexed on 2010/04/22 23:03 UTC
Read the original article Hit count: 188

Filed under:
|
|

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 ?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about routes