HowTo: Using MvcContrib.Pagination without Using MvcContrib.Grid View

It started as a question, but turned into a solution, as I experimented! So I thought I would share this with all of you. My question is:

How to use MvcContrib.Pagination without using MvcContrib.Grid View?

My answer is below ...

+3
source share
1 answer

I am creating a support ticket system (Iโ€™m kind of new to C # - got a lot of pointers from NerdDinner), and I want to use some kind of swap library to help with the presentation. I found MvcContrib.Pagination and I got it to work. My view does not use MvcContrib.Grid, as it is normal.

List.aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MyProject.Areas.HelpDesk.Models.hd_Ticket>>" %>
<%@ Import Namespace="MyProject.Areas.HelpDesk.Controllers" %>
<%@ Import Namespace="MvcContrib.Pagination" %>

<h2>Help Desk Tickets (showing <%= Model.Count() %> of <%= ViewData["totalItems"] %>)</h2>     

<% foreach (var item in Model) { %>
    <h3><%= Html.Encode(item.Subject)%></h3>
<% } %>

<p><%= Html.Pager((IPagination)Model)%></p>

() TicketController.cs:

TicketRepository ticketRepository = new TicketRepository();

public ActionResult List(int? page, int? pageSize)
{
    IPagination<hd_Ticket> tickets = null;

    int dPageSize = 50;
    int totalItems;

    tickets = ticketRepository.GetTickets().ToList().AsPagination(page ?? 1, pageSize ?? dPageSize);
    ViewData["totalItems"] = tickets.TotalItems;

    return View("List", tickets);
}

, IQueryable. TicketRepository.cs:

public class TicketRepository
{
    private HelpDeskDataContext db = new HelpDeskDataContext();

    public IQueryable<hd_Ticket> FindAllTickets()
    {
        return from ticket in db.hd_Tickets
               orderby ticket.CreatedDate descending
               select ticket;
    }
}

, - # ASP.NET MVC , . NerdDinner, :

http://nerddinnerbook.s3.amazonaws.com/Intro.htm

:)

+6

Source: https://habr.com/ru/post/1717854/


All Articles