与MVC3 C#分页最简单的方法? [英] The easiest way for paging with MVC3 C#?

查看:198
本文介绍了与MVC3 C#分页最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有MVC3 C#一个网站项目中,我在我看来检索表从数据库和presents信息。我想使用分页显示每页最多五类线。一直在寻找互联网上的教程,但他们似乎都非常先进去实现它。什么是与MVC3分页最简单的方法?

Have a website project in MVC3 C # where I retrieve information from the database and presents in a table in my view. I want to use paging to show up to five lines per page. Have been looking for tutorials on Internet but they all seem very advanced to achieve it. What is the easiest way for paging with MVC3?

在看图片的左下角,看看我说的分页

Look in the lower left corner of the picture to see what I mean by paging

分页

推荐答案

尝试 PagedList 。有对MVC中的的NuGet包

Try PagedList. There's a NuGet package for MVC.

@{
    ViewBag.Title = "Product Listing"
}
@using PagedList.Mvc; //import this so we get our HTML Helper
@using PagedList; //import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)

<!-- import the included stylesheet for some (very basic) default styling -->
<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />

<!-- loop through each of your products and display it however you want. we're just printing the name here -->
<h2>List of Products</h2>
<ul>
    @foreach(var product in ViewBag.OnePageOfProducts){
        <li>@product.Name</li>
    }
</ul>

<!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
@Html.PagedListPager( (IPagedList)ViewBag.OnePageOfProducts, page => Url.Action("Index", new { page }) )

这篇关于与MVC3 C#分页最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆