views:

261

answers:

1

I am using the pager provided by Martijn Boland to implementing paging in my Asp.Net Mvc 2 application.

My form uses the GET method to send all parameters to the querystring, it is a search form with several form elements.

<% using (Html.BeginForm("SearchResults", "Search", FormMethod.Get))
       {%>

On the SearchResults View I am trying to implement paging:

<div class="pager">
    <%= Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount, 
        new { Request.QueryString })%>
</div>

The Html.Pager has some overloads which I am not too clear on how to use. The Request.QueryString makes the querystring look like this:

http://localhost:1155/Search/SearchResults?QueryString=Distance%3D10%26txtZip%3D%26cb&amp;page=2

Should it not be like this?

http://localhost:1155/Search/SearchResults?Distance=20&amp;txtZip=10021&amp;page=2
+1  A: 

my guess would be to write your pager like this

<%= Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount,  new { Distance = Request["Distance"], txtZip = Request["txtZip"] })%>

but it's only a guess, i've never used that...

Edit: see ASP.Net MVC Keeping action parameters between postbacks so you have to create a RouteValueDictionary from the QueryString which is a NameValueCollection.

moi_meme
There are more than two parameters, so I am trying to avoid listing them separately.
Picflight
I'd like so second this answer (the Edit: part). Create a helper function to convert querystring params to a RouteValueDictionary and feed that to the Pager. Maybe ASP.NET MVC already contains such a function?
martijnboland
+1 for responding Martijn.
Picflight