title: Dynamically return a variable number of models with ajax
body: <p>I currently have the code as seen below, I pass data from controller to my view and then display the data. </p>
  
  <p>Using ajax I would like to adapt my view to be more dynamic with the data passed through the controller. </p>
  
  <p>Goal: </p>
  
  <p>At the moment, the view returns a list of names from people the user follows. I would like to have a set variable e.g. maxShow = 5, and when the page is loaded a maximum of 5 people will be shown. When the user scrolls to the bottom of the page, ajax will then get and place the next 5 onto the dom and this should be a continuous cycle.</p>
  
  <p>I've been coming up with some rough pseudo code with the jquery as seen below for how to load every person dynamically, but cannot figure out how to limit the call to 5 people, and then another 5 people so on when scrolled to the very bottom. The only half-solution I have is to change my following query to .take(5) at the end. </p>
  
  <pre><code>$(window).scroll(function() {
     if($(window).scrollTop() + $(window).height() == $(document).height()) {
         // Make an Ajax call 
       $.get("/Following",function(data){
        $("#div").html(data);
        });
       }
  </code></pre>
  
  <hr>
  
  <pre><code>        [Authorize]
          public ActionResult Following()
          {
              var userId = User.Identity.GetUserId();
  
              var following = _context.Followings
                              .Where(x =&gt; x.FollowerId == userId)
                              .Select(a =&gt; a.Followee)
                              .ToList();
  
              var viewModel = new FollowingViewModel
              {
                  Following = following,
                  ShowActions = User.Identity.IsAuthenticated,
                  Heading = "People I'm following"
              };
  
              return View("following", viewModel);
          }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@model Gighub3.ViewModels.FollowingViewModel
  
  @{
      ViewBag.Title = "Following";
  }
  
  &lt;h1&gt;@Model.Heading&lt;/h1&gt;
  
  &lt;ul&gt;
      @foreach (var following in Model.Following)
      {
          &lt;li&gt;@following.Name&lt;/li&gt;
      }
  &lt;/ul&gt;
  </code></pre>