Twitter style paging with ASP.NET MVC and jQuery

来源:互联网 发布:js修改url 不跳转 编辑:程序博客网 时间:2024/06/09 19:53
来源:http://joelabrahamsson.com/twitter-style-paging-with-aspnet-mvc-and-jquery/
public class HomeController : Controller{    private const int defaultEntryCount = 10;    public ActionResult Index(int? entryCount)    {        if (!entryCount.HasValue)            entryCount = defaultEntryCount;        //Retrieve the first page with a page size of entryCount         int totalItems;        IEnumerable<Entry> entries = GetLatestEntries(1, entryCount.Value, out totalItems);                if (entryCount < totalItems)            AddMoreUrlToViewData(entryCount.Value);        return View(entries);    }    private void AddMoreUrlToViewData(int entryCount)    {        ViewData["moreUrl"] = Url.Action("Index", "Home", new { entryCount = entryCount + defaultEntryCount });    }}


public ActionResult Index(int? entryCount){    if (!entryCount.HasValue)        entryCount = defaultEntryCount;    int totalItems;    if(Request.IsAjaxRequest())    {        int page = entryCount.Value / defaultEntryCount;        //Retrieve the page specified by the page variable with a page size o defaultEntryCount        IEnumerable<Entry> pagedEntries = GetLatestEntries(page, defaultEntryCount, out totalItems);                if(entryCount < totalItems)            AddMoreUrlToViewData(entryCount.Value);                return View("EntryTeaserList", pagedEntries);    }    //Retrieve the first page with a page size of entryCount    IEnumerable<Entry> entries = GetLatestEntries(1, entryCount.Value, out totalItems);        if (entryCount < totalItems)        AddMoreUrlToViewData(entryCount.Value);    return View(entries);}


0 0
原创粉丝点击