I have my pagination with the view and the action with the view name correct and working, Now I have another action that gets a custom set of data that uses the same model in the view just with different results. How can I make my pagination work with this separate action. In the separate action I originally called View(“viewname”, Model) to open my view with this data.
public async Task<ActionResult> UserTimeSheets(string id, int? page)
{
var userTimeSheets = await (from times in context.TimeSheetMaster
where times.UserId == id
select new TimeSheetMasterModel()
{
TimeSheetMasterId = times.TimeSheetMasterId,
UserId = times.UserId.ToString(),
IdShortened = times.UserId.Substring(0,10)
}).ToListAsync();
int pageSize = 3;
int pageNumber = (page ?? 1);
TempData["PanelHeader"] = "Your TimeSheets";
return View(userTimeSheets.ToPagedList(pageNumber, pageSize));
}
{
var approved = await (from m in context.TimeSheetMaster
where m.TimeSheetStatus == 2
&& m.UserId == userid
select new TimeSheetMasterModel()
{
TimeSheetMasterId = m.TimeSheetMasterId,
IdShortened = m.UserId.Substring(0,8),
TotalHours = m.TotalHours,
Comment = m.Comment,
}).ToListAsync();
int pageSize = 3;
int pageNumber = (page ?? 1);
TempData["PanelHeader"] = "Your Approved TimeSheets";
return View("UserTimeSheets", approved.ToPagedList(pageNumber, pageSize));
}
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@*if (TempData["PageHeader"] == "Your Approved TimeSheets")
{
@Html.PagedListPager(Model, page => Url.Action("UserApproveTimes", new { page }))
}
else
{
@Html.PagedListPager(Model, page => Url.Action("UserTimeSheets", new { page }))
}*@
@Html.PagedListPager(Model, page => Url.Action("UserTimeSheets", new { page = page}),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "table"
}))
What I have tried:
. I can get the pagination to show the correct number of pages and loads the first page correctly but as soon as I click the next page it shows no data in the view. I am using PagedList for my pagination. Here is my code with pagination working and the action that shows the first page of data. I tried using ajax thinking maybe itll work because the page doesn’t need to refresh but it does the same thing as before the 2nd page is empty.