Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Can I Convert My Paging Functionality To Use AJAX Insead?
    primarykey
    data
    text
    <p>I currently have pagination working in my MVC 3 project using the PagedList library (https://github.com/TroyGoode/PagedList).</p> <p>I would like to convert this code to update the page using ajax with the new results rather then refreshing the whole page. I'm not really sure how to go about that. Im rather new to MVC coming from Webforms. Any help would be greatly appreciated!</p> <p>Heres my code:</p> <p>Home Controller:</p> <pre><code>//##################################### // ActionResult = Retrieve Comments //##################################### [ChildActionOnly] public ActionResult _Comments(int ProductID, int? Page) { //Perform the Database Query. try { //SQL Query - Get * records var Model = from r in DB.Comments where r.ProductID == ProductID select r; //Page number passed in via url. Default to 1 if not specified. var PageNumber = Page ?? 1; //Grab 6 results from the result set. var Results = Model.ToPagedList(PageNumber, 6); //Store Paged Result set in ViewBag for Paging. ViewBag.Results = Results; //Store in ViewBag for display (Page 1 of 43) ViewBag.PageNumber = PageNumber; //Get Total Pages: Divide Total Records by 6 Records per page. ViewBag.PageCount = Model.Count() / 6 + 1; //Return Records to my view. return PartialView(Results); } //There was an error. catch { //ViewBag.ErrorMessage = ex; return PartialView("Error"); } } </code></pre> <p>PartialView: _Comments</p> <pre><code>@model IEnumerable&lt;DH.Models.Comment&gt; @using PagedList.Mvc; @using PagedList; @{ //No Comments Yet if (@Model.Count() == 0) { &lt;div id="CommentStatus"&gt;Be the first to comment on this product!&lt;/div&gt; } //There are comments! else { foreach (var item in Model) { //html for writing out the comments... } } } &lt;div&gt;Page @ViewBag.PageNumber of @ViewBag.PageCount&lt;/div&gt; @Html.PagedListPager((IPagedList)ViewBag.Results, Page =&gt; Url.Action("Index", new { Page = Page }), new PagedListRenderOptions { LinkToPreviousPageFormat = "&lt; Prev", LinkToNextPageFormat = "Next &gt;", LinkToLastPageFormat = "&amp;Uacute;ltima &gt;&gt;" }) </code></pre> <p>Model</p> <pre><code>namespace DH.Models { public class Comment { public int CommentID { get; set; } public int ProductID { get; set; } public string Author { get; set; } public string Message { get; set; } public DateTime MessageDate { get; set; } public int ThumbsUp { get; set; } public int ThumbsDown { get; set; } public string IP { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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