Skip to content

Commit

Permalink
Added MVC paging control (HTML helper) and two more helper properties…
Browse files Browse the repository at this point in the history
… to IPagedList that get the index of the first and last items on the page.
  • Loading branch information
troygoode committed Mar 27, 2011
1 parent 82df0b6 commit 76bd186
Show file tree
Hide file tree
Showing 26 changed files with 1,040 additions and 31 deletions.
10 changes: 10 additions & 0 deletions src/PagedList.Mvc.Example/Content/PagedList.css
@@ -0,0 +1,10 @@
.PagedList-control > ul{
display: block;
margin: 0;
padding: 0;
list-style: none;
}
.PagedList-control > ul > li{
margin: .25em;
display: inline-block;
}
68 changes: 68 additions & 0 deletions src/PagedList.Mvc.Example/Content/Site.css
@@ -0,0 +1,68 @@
body
{
font-size: 75%;
font-family: Verdana, Tahoma, Arial, "Helvetica Neue", Helvetica, Sans-Serif;
color: #232323;
background-color: #fff;
}

/* Styles for basic forms
-----------------------------------------------------------*/

fieldset
{
border:1px solid #ddd;
padding:0 1.4em 1.4em 1.4em;
margin:0 0 1.5em 0;
}

legend
{
font-size:1.2em;
font-weight: bold;
}

textarea
{
min-height: 75px;
}

.editor-label
{
margin: 1em 0 0 0;
}

.editor-field
{
margin:0.5em 0 0 0;
}


/* Styles for validation helpers
-----------------------------------------------------------*/
.field-validation-error
{
color: #ff0000;
}

.field-validation-valid
{
display: none;
}

.input-validation-error
{
border: 1px solid #ff0000;
background-color: #ffeeee;
}

.validation-summary-errors
{
font-weight: bold;
color: #ff0000;
}

.validation-summary-valid
{
display: none;
}
28 changes: 28 additions & 0 deletions src/PagedList.Mvc.Example/Controllers/HomeController.cs
@@ -0,0 +1,28 @@
using System.Linq;
using System.Web.Mvc;

namespace PagedList.Mvc.Example.Controllers
{
public class HomeController : Controller
{
public object Index(int? page)
{
// return a 404 if user browses to before the first page
if (page.HasValue && page < 1)
return HttpNotFound();

// retrieve list from database/wherever (in this case Enumerable.Range) and page it
const int pageSize = 20;
var listAll = Enumerable.Range(1, 500);
var listPaged = listAll.ToPagedList(page.HasValue ? page.Value - 1 : 0, pageSize);

// return a 404 if user browses to pages beyond last page. special case first page if no items exist
if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount)
return HttpNotFound();

// pass the paged list to the view and render
ViewBag.Numbers = listPaged;
return View();
}
}
}
1 change: 1 addition & 0 deletions src/PagedList.Mvc.Example/Global.asax
@@ -0,0 +1 @@
<%@ Application Codebehind="Global.asax.cs" Inherits="PagedList.Mvc.Example.MvcApplication" Language="C#" %>
40 changes: 40 additions & 0 deletions src/PagedList.Mvc.Example/Global.asax.cs
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace PagedList.Mvc.Example
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

}

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
}
127 changes: 127 additions & 0 deletions src/PagedList.Mvc.Example/PagedList.Mvc.Example.csproj
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{262216DA-247E-4217-B208-FB82AD664305}</ProjectGuid>
<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PagedList.Mvc.Example</RootNamespace>
<AssemblyName>PagedList.Mvc.Example</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>false</UseIISExpress>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.WebPages" />
<Reference Include="System.Web.Helpers" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\PagedList.css" />
<Content Include="Global.asax" />
<Content Include="Content\Site.css" />
<Content Include="Web.config" />
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Views\Web.config" />
<Content Include="Views\_ViewStart.cshtml" />
<Content Include="Views\Shared\Error.cshtml" />
<Content Include="Views\Shared\_Layout.cshtml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\PagedList.Mvc\PagedList.Mvc.csproj">
<Project>{3E8629F8-D927-4D5F-A351-47DDE2AE37D1}</Project>
<Name>PagedList.Mvc</Name>
</ProjectReference>
<ProjectReference Include="..\PagedList\PagedList.csproj">
<Project>{DA52D7C3-B871-48EC-B009-AC782AD50266}</Project>
<Name>PagedList</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Views\Home\Index.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target> -->
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>2236</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
35 changes: 35 additions & 0 deletions src/PagedList.Mvc.Example/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PagedList.Mvc.Example")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("PagedList.Mvc.Example")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("145aabf4-7898-4833-98d4-b059caad9315")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
30 changes: 30 additions & 0 deletions src/PagedList.Mvc.Example/Views/Home/Index.cshtml
@@ -0,0 +1,30 @@
@{
ViewBag.Title = "Index";
}
@using PagedList;
@using PagedList.Mvc;

<h2>PagedList.Mvc.Example Website</h2>

<p>Example of paging a list:</p>

<h3>List of @ViewBag.Numbers.TotalItemCount Numbers (Page Size: @ViewBag.Numbers.PageSize, Current Page: @ViewBag.Numbers.PageNumber)</h3>
<ul>
@foreach(var i in ViewBag.Numbers){
<li>@i</li>
}
</ul>

<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />

<h3>Default Paging Control</h3>
@Html.PagedListPager((IPagedList)ViewBag.Numbers, page => Url.Action("Index", new { page = page + 1 }))

<h3>Minimal Paging Control</h3>
@Html.PagedListPager((IPagedList)ViewBag.Numbers, page => Url.Action("Index", new { page = page + 1 }), PagedListRenderOptions.Minimal)

<h3>Minimal Paging Control w/ Page Count Text</h3>
@Html.PagedListPager((IPagedList)ViewBag.Numbers, page => Url.Action("Index", new { page = page + 1 }), PagedListRenderOptions.MinimalWithPageCountText)

<h3>Minimal Paging Control w/ Item Count Text</h3>
@Html.PagedListPager((IPagedList)ViewBag.Numbers, page => Url.Action("Index", new { page = page + 1 }), PagedListRenderOptions.MinimalWithItemCountText)
15 changes: 15 additions & 0 deletions src/PagedList.Mvc.Example/Views/Shared/Error.cshtml
@@ -0,0 +1,15 @@
@{
Layout = null;
}

<!DOCTYPE html>
<html>
<head>
<title>Error</title>
</head>
<body>
<h2>
Sorry, an error occurred while processing your request.
</h2>
</body>
</html>
10 changes: 10 additions & 0 deletions src/PagedList.Mvc.Example/Views/Shared/_Layout.cshtml
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
</head>
<body>
@RenderBody()
</body>
</html>

0 comments on commit 76bd186

Please sign in to comment.