......
        <% Products cProduct = new Products(); %>
        <% for (int i = 0; i < Model.Count; i++){%>
        <% cProduct = Model[i]; %>
        <%  if (i % 2 == 0){%>
        <tr class="single" onmouseover="MouseOver(event)" onmouseout="MouseOut(event)" onclick="MouseDown(event)">
            <td>
                <%= cProduct.ProductID%>
            </td>
            <td>
                <%=cProduct.ProductName%>
            </td>
            <td>
                <%= cProduct.QuantityPerUnit%>
            </td>
            <td>
                <%=cProduct.UnitPrice%>
            </td>
            <td>
                <%= cProduct.UnitsInStock%>
            </td>
            <td>
                <%= cProduct.UnitsOnOrder%>
            </td>
            <td>
                <%= cProduct.ReorderLevel%>
            </td>
            <td>
            </td>
        </tr>
        <% } %>
        <% else
            { %>
        <tr class="double" onmouseover="MouseOver(event)" onmouseout="MouseOut(event)" onclick="MouseDown(event)">
            <td>
                <%= cProduct.ProductID%>
            </td>
            <td>
                <%=cProduct.ProductName%>
            </td>
            <td>
                <%= cProduct.QuantityPerUnit%>
            </td>
            <td>
                <%=cProduct.UnitPrice%>
            </td>
            <td>
                <%= cProduct.UnitsInStock%>
            </td>
            <td>
                <%= cProduct.UnitsOnOrder%>
            </td>
            <td>
                <%= cProduct.ReorderLevel%>
            </td>
            <td>
            </td>
        </tr>
        <% } %>
        <% }  %>
    </table>
    <%--结果区结束(end)--%>
    <%--分页区开始(begin)--%>
    <%=Html.Pager(Model, new PagerOptions() { PageIndexParameterName = "ProductID" })%>
    <%--分页区结束(end)--%>
命名空间
<%@ Import Namespace="MvcApp.Models.Models" %>
<%@ Import Namespace="Webdiyer.WebControls.Mvc"%>
Inherits="System.Web.Mvc.ViewPage<PagedList<Products>> 类型

解决方案 »

  1.   


      public ActionResult List()
            {
                Models.DAL.DAL_Products cDALProducts = new Models.DAL.DAL_Products();            PagedList<Products> products = cDALProducts.GetPageList(1, 10);            return View(products);
            } public PagedList<Models.Products> GetPageList(int p_intCurrentIndex, int p_intSize)
            {            SqlParameter[] parameters = {
                                                new SqlParameter("@Tables", SqlDbType.NVarChar, 400),
                                                new SqlParameter("@PrimaryKey", SqlDbType.NVarChar, 100),
                                                new SqlParameter("@pagesize", SqlDbType.Int, 4),
                                                new SqlParameter("@pageindex", SqlDbType.Int, 4)
                                            };
                parameters[0].Value = "Products";
                parameters[1].Value = "ProductID";
                parameters[2].Value = p_intSize;
                parameters[3].Value = p_intCurrentIndex;            List<Models.Products> listProducts = new List<Models.Products>();            using (SqlDataReader sdrProducts = SqlHelper.ExecuteReader(_strSQLConnectionString, CommandType.StoredProcedure, "sp_MVCPage", parameters))
                {
                    while (sdrProducts.Read())
                    {
                        Models.Products cProduct = new Models.Products();                    cProduct.ProductID = sdrProducts.GetInt32(0);
                        cProduct.ProductName = sdrProducts.GetString(1);
                        cProduct.SupplierID = sdrProducts.GetInt32(2);
                        cProduct.CategoryID = sdrProducts.GetInt32(3);
                        cProduct.QuantityPerUnit = sdrProducts.GetString(4);
                        cProduct.UnitPrice = sdrProducts.GetDecimal(5);
                        cProduct.UnitsInStock = sdrProducts.GetInt16(6);
                        cProduct.UnitsOnOrder = sdrProducts.GetInt16(7);
                        cProduct.ReorderLevel = sdrProducts.GetInt16(8);
                        cProduct.Discontinued = sdrProducts.GetBoolean(9);                    listProducts.Add(cProduct);
                    }
                }            PagedList<Models.Products>  pageListProducts = new PagedList<Models.Products>(listProducts, p_intCurrentIndex, p_intSize);
                return pageListProducts;
            }
    能显示10 笔数据,但是分页 显示 不出来,我刚学 不知道 哪里弄的不对
      

  2.   

    用PagedList<T>的第二个构造函数:public PagedList(IEnumerable<T> items, int pageIndex, int pageSize, int totalItemCount)
    而不是第一个,你取的数据源是当前页数据而不是所有数据,却把它当成所有要分页的数据传递给了PagedList<T>构造函数,这样就导致要分页的总记录数就等于当前页的总记录数,也就是只有一页数据。