Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am building a Help Desk Ticketing System (I am kind of a C# newbie - got many pointers from NerdDinner) and I wish to use some sort of paging library to help with the view. I found MvcContrib.Pagination and I got it to work for a view. My view does NOT use MvcContrib.Grid because it is custom.</p> <p>Scaled down version of my view <strong>List.aspx</strong> :</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;IEnumerable&lt;MyProject.Areas.HelpDesk.Models.hd_Ticket&gt;&gt;" %&gt; &lt;%@ Import Namespace="MyProject.Areas.HelpDesk.Controllers" %&gt; &lt;%@ Import Namespace="MvcContrib.Pagination" %&gt; &lt;h2&gt;Help Desk Tickets (showing &lt;%= Model.Count() %&gt; of &lt;%= ViewData["totalItems"] %&gt;)&lt;/h2&gt; &lt;% foreach (var item in Model) { %&gt; &lt;h3&gt;&lt;%= Html.Encode(item.Subject)%&gt;&lt;/h3&gt; &lt;% } %&gt; &lt;p&gt;&lt;%= Html.Pager((IPagination)Model)%&gt;&lt;/p&gt; </code></pre> <p>My controller (part) <strong>TicketController.cs</strong> :</p> <pre><code>TicketRepository ticketRepository = new TicketRepository(); public ActionResult List(int? page, int? pageSize) { IPagination&lt;hd_Ticket&gt; tickets = null; int dPageSize = 50; int totalItems; tickets = ticketRepository.GetTickets().ToList().AsPagination(page ?? 1, pageSize ?? dPageSize); ViewData["totalItems"] = tickets.TotalItems; return View("List", tickets); } </code></pre> <p>I am using the repository pattern which is returning the results as IQueryable. Here is part of the <strong>TicketRepository.cs</strong> file:</p> <pre><code>public class TicketRepository { private HelpDeskDataContext db = new HelpDeskDataContext(); public IQueryable&lt;hd_Ticket&gt; FindAllTickets() { return from ticket in db.hd_Tickets orderby ticket.CreatedDate descending select ticket; } } </code></pre> <p>All this may be trivial to some, but if someone like me is trying to learn C# and ASP.NET MVC and paging, then this may be useful. I recommend newbies to do the NerdDinner tutorial found at:</p> <p><a href="http://nerddinnerbook.s3.amazonaws.com/Intro.htm" rel="nofollow noreferrer">http://nerddinnerbook.s3.amazonaws.com/Intro.htm</a></p> <p>:)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload