ASP.Net MVC Keeping action parameters between postbacks

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2008-09-23T16:26:15Z Indexed on 2010/03/13 2:17 UTC
Read the original article Hit count: 565

Say I have a page that display search results. I search for stackoverflow and it returns 5000 results, 10 per page. Now I find myself doing this when building links on that page:

<%=Html.ActionLink("Page 1", "Search", new { query=ViewData["query"], page etc..%>
<%=Html.ActionLink("Page 2", "Search", new { query=ViewData["query"], page etc..%>
<%=Html.ActionLink("Page 3", "Search", new { query=ViewData["query"], page etc..%>
<%=Html.ActionLink("Next", "Search", new { query=ViewData["query"], page etc..%>

I dont like this, I have to build my links with careful consideration to what was posted previously etc..

What I'd like to do is

<%=Html.BuildActionLinkUsingCurrentActionPostData
        ("Next", "Search", new { Page = 1});

where the anonymous dictionary overrides anything currently set by previous action.

Essentially I care about what the previous action parameters were, because I want to reuse, it sounds simple, but start adding sort and loads of advance search options and it starts getting messy.

Im probably missing something obvious

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-routing