title: MVC 4 Using Paged List in a partial View
body: <p>I am trying to implement PagedList in a partial view.</p>
  
  <p>Describing the view setup.  I have <code>Controller A with ViewA</code>.  This is the parent view and has its own model.  Then I have <code>Controller B with PartialViewB</code> and has its own model as well.  Then I have a Div in <code>ViewA</code> that will be used to display the <code>PartialViewB</code>.  I can load in <code>PartialViewB</code> after hitting a button and then hide the view after hitting the button again.  Within the <code>PartialViewB</code> is the PagedList.  Hitting the next page button loads the next page, but loads it in its own page, not in the <code>ViewA</code> as it was before.</p>
  
  <p>I can load up more code as needed, but for now here is the Pager</p>
  
  <pre><code>&lt;br /&gt;
      Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
  
      @Html.PagedListPager(Model, page =&gt; Url.Action("ViewComments",
      new { courseID = @ViewBag.courseID, page }), 
      new PagedListRenderOptions { MaximumPageNumbersToDisplay = 5, DisplayLinkToFirstPage = PagedListDisplayMode.IfNeeded, 
          DisplayLinkToLastPage = PagedListDisplayMode.IfNeeded })
  </code></pre>
  
  <p>::EDIT::</p>
  
  <p>Parent View</p>
  
  <pre><code>&lt;div class="Comments"&gt;
      &lt;input type="button" id="View" class="CommentsButton" value="View Comments"/&gt;
      &lt;input type="hidden" id="Hidden" value="false" /&gt;
  &lt;/div&gt;
  &lt;div id="Comments"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>PartialView</p>
  
  <pre><code>@model PagedList.IPagedList&lt;QIEducationWebApp.Models.CourseComment&gt;
  @using PagedList.Mvc;
  
  @{
      ViewBag.Title = "Comments";
  }
  
  &lt;h2&gt;Comments!&lt;/h2&gt;
  
  &lt;table&gt;
  
  @foreach (var item in Model)
  {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.CommentDate)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.UserName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.CommentText)
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;appSettings&gt;
    &lt;add key="UnobtrusiveJavaScriptEnabled" value="true"/&gt; 
  &lt;/appSettings&gt;
  
  &lt;br /&gt;
      Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
  
      @Html.PagedListPager(Model, page =&gt; Url.Action("ViewComments",
      new { courseID = @ViewBag.courseID, page }),
              PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
                  new PagedListRenderOptions { MaximumPageNumbersToDisplay = 5, DisplayLinkToFirstPage = PagedListDisplayMode.IfNeeded, 
                  DisplayLinkToLastPage = PagedListDisplayMode.IfNeeded },
                  new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "Comments" }))
  </code></pre>
  
  <p>BundleConfig.cs</p>
  
  <pre><code>public class BundleConfig
      {
          // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
          public static void RegisterBundles(BundleCollection bundles)
          {
              bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                          "~/Scripts/jquery-{version}.js"));
  
              bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                          "~/Scripts/jquery-ui-{version}.js"));
  
              bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                          "~/Scripts/jquery.unobtrusive*",
                          "~/Scripts/jquery.validate*"));
  
              // Use the development version of Modernizr to develop with and learn from. Then, when you're
              // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
              bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                          "~/Scripts/modernizr-*"));
  
              bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css", "~/Content/PagedList.css"));
  
              bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                          "~/Content/themes/base/jquery.ui.core.css",
                          "~/Content/themes/base/jquery.ui.resizable.css",
                          "~/Content/themes/base/jquery.ui.selectable.css",
                          "~/Content/themes/base/jquery.ui.accordion.css",
                          "~/Content/themes/base/jquery.ui.autocomplete.css",
                          "~/Content/themes/base/jquery.ui.button.css",
                          "~/Content/themes/base/jquery.ui.dialog.css",
                          "~/Content/themes/base/jquery.ui.slider.css",
                          "~/Content/themes/base/jquery.ui.tabs.css",
                          "~/Content/themes/base/jquery.ui.datepicker.css",
                          "~/Content/themes/base/jquery.ui.progressbar.css",
                          "~/Content/themes/base/jquery.ui.theme.css"));
          }
      }
  </code></pre>