如何在ASP中实现分页。净MVC吗?

[英]How do you implement paging in ASP.NET MVC?


Currently, I'm using a strategy found on many blog posts. Basically, the URL contains the page number (e.g. /Users/List/5 will give you the users on page 5 of your paged list of users). However, I'm not running into a situation where one page must list two separate paged lists. How do I go about doing this using ASP.NET MVC? Do I simply provide two url parameters (e.g. /Users/List?page1=1&page2=2)? Is there a better way by using partial views?

目前,我正在使用在许多博客文章中找到的策略。基本上,该URL包含页码(例如/Users/List/5将给出您的页面列表的第5页上的用户)。然而,我并没有遇到这样的情况:一个页面必须列出两个单独的页面列表。我如何使用ASP来实现这个。净MVC吗?我是否只提供两个url参数(例如/Users/List?page1=1&page2=2)?使用局部视图有更好的方法吗?

4 个解决方案

#1


10  

Ignoring routes for just a minute, you'll just keep the state of the 2 different pages in the URL as querystring parameters.

在一分钟内忽略路由,您只需将URL中两个不同页面的状态保持为querystring参数。

mysite.com/foo?list1page=2&list2page=8

mysite.com/foo?list1page=2&list2page=8

Then you build the data/pagers accordingly. The pager links will just update the url.

然后相应地构建数据/呼机。寻呼机链接只会更新url。

You can get creative with routes to create more friendly URLs, but I think querystring params are perfectly acceptable here.

您可以通过路由创建更友好的url,但是我认为查询字符串params是完全可以接受的。

#2


3  

I've found ASP.NET MvcPager on the official asp.net site.

我发现ASP。NET MvcPager在官方asp.net站点上。

#3


2  

If you use query parameters then the page links in each list have to know about each other in-order to pass both parameters.

如果使用查询参数,那么每个列表中的页链接必须相互了解才能传递这两个参数。

If the two lists are independent of each other then you can update them individually using jquery & ajax. Simply place each list in their own div as a partial view.

如果这两个列表彼此独立,那么您可以使用jquery和ajax分别更新它们。只需将每个列表放在它们自己的div中作为局部视图。

<div id="list1"><%= Html.RenderPartial ("ListA") %></div>
<div id="list2"><%= Html.RenderPartial ("ListB") %></div>

Lookup ajaxSubmit from the jQuery Form plugin for an easy way to update the lists.

查找jQuery表单插件中的ajaxSubmit,以获得更新列表的简单方法。

#4


1  

PagedList.Mvc is a really easy to use plugin, and is available via Nuget too.

PagedList。Mvc是一个很容易使用的插件,并且可以通过Nuget获得。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2008/11/15/c672034a48581f5672389d9e182be876.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号