ASP.Net MVC Keeping action parameters between postbacks
- by Matt
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