开发者

How to page while maintaining the querystring values in ASP.Net Mvc 2

开发者 https://www.devze.com 2022-12-26 08:19 出处:网络
I am using the pager provided by Martijn Boland to implementing paging in my Asp.Net Mvc 2 application.

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.开发者_JS百科QueryString makes the querystring look like this:

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

Should it not be like this?

http://localhost:1155/Search/SearchResults?Distance=20&txtZip=10021&page=2


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消