问题描述
这开始作为一个问题,而是变成了一个解决方案,我做了一些尝试!所以,我想我会与大家分享。我的问题是:
This started as a question, but turned into a solution as I did some experimenting! So I thought I would share this with you all. My question WAS:
如何使用MvcContrib.Pagination不使用MvcContrib.Grid查看?
我的回答是低于...
My answer is below...
推荐答案
我建立一个帮助台售票系统(我是那种一个C#新手 - 得到了很多三分球从NerdDinner范例),我想使用某种分页库帮助视图。我发现MvcContrib.Pagination,我得到它的视图中工作。我的看法不使用MvcContrib.Grid因为它是定制的。
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.
我的观点的缩小版本的 List.aspx
Scaled down version of my view 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;
}
}
这一切都可能是微不足道的一些,但如果像我是想学C#和ASP.NET MVC和寻呼,那么这可能是有用的。我建议新手做在发现的NerdDinner教程:
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:
:)
这篇关于Howto:如何使用MvcContrib.Pagination不使用MvcContrib.Grid查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!