This is similar to paging except that you retain the previous fetches. Your view model needs to have one more property of a helper class:
public class PagingInfo
{
public int TotalItems { get; set; }
public int ItemsPerPage { get; set; }
public int CurrentPage { get; set; }
public int TotalPages
{
get { return (int)Math.Ceiling((decimal)TotalItems / ItemsPerPage); }
}
}
public class QuestionsListViewModel
{
public IEnumerable<Question> Questions { get; set; }
public PagingInfo PagingInfo { get; set; }
}
And when you render the QuestionsListViewModel, use a similar Razor Code:
@foreach (var p in Model.Questions)
{
// render Questions
}
@Html.ActionLink("Load next 25 items", "Questions", "Controller", new { page = Model.PagingInfo.CurrentPage + 1 }))
Questions is your Controller Action as follows:
public ViewResult Questions(int page = 1)
{
QuestionsListViewModelmodel = new QuestionsListViewModel
{
// we need to get all items till now to render again
Questions = repository.Questions
.Take(page * PageSize),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = 25,
TotalItems = repository.Questions.Count()
}
};
return View(model);
}
You can actually use the TotalItems property to give a smart message for loading next items.
If you don't want to go the MVC way, then you can leverage client side scripting to achieve the same.