I have the following Action method , which mainly display a list of objects and apply the IPaged list to it :-
[OutputCache(CacheProfile = "short", Location = OutputCacheLocation.Client,VaryByHeader="X-Requested-With" ,VaryByParam = "page")]
public ActionResult Index(int? typeid, int page = 1, string searchTerm ="")
{
int pagesize;
ViewBag.Techtypes = repository.GetAllTechnologyType2().ToList();
var audit = repository.AllIncludingTechnologyAudit(searchTerm.Trim(),typeid,auditinfo => auditinfo.Technology,auditinfo2=>auditinfo2.TechnologyType,auditinfo3=>auditinfo3.AuditAction).OrderByDescending(a=>a.ID)
.ToPagedList(page,300);
if (Request.IsAjaxRequest())
{
ViewBag.FromSearch = true;
return PartialView("_AuditTable", audit);
}
return View(audit);
}
The Index view looks as follow:-
model IPagedList<TMS.Models.TechnologyAudit>
@{
ViewBag.Title = "Technology Audit List";
}
<div style="float:right">
@using (Ajax.BeginForm("Index","TechnologyAudit",
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "Searchprogress",
UpdateTargetId = "AuditTable"
}))
{
<span class="f">Search By Tag</span> <input placeholder="Search by Tag.." name="searchTerm" type="text" />
<input class="btn btn-success" type="submit" value="search" />
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="Searchprogress" />
}
@using (Ajax.BeginForm("Index","TechnologyAudit",
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "Searchprogress2",
UpdateTargetId = "AuditTable"
}))
{
<span class="f">Asset Type</span>
@Html.DropDownList("typeid", ((IEnumerable<TMS.Models.TechnologyType>)ViewBag.Techtypes).Select(option => new SelectListItem {
Text = (option == null ? "None" :option.Name),
Value = option.AssetTypeID.ToString()
}), "All")
<input class="btn btn-success" type="submit" value="search" />
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="Searchprogress2" />
}
</div>
@Html.Partial("_AuditTable", Model)
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
And the _AuditTable
view looks as follow:-
@model IPagedList<TMS.Models.TechnologyAudit>
<div id="AuditTable">
<div class="row-fluid sortable" >
<div class="box span12">
<div class="box-header well" data-original-title id="auditlist">
<h2><i class="icon-home"></i> Audit Info </h2>
<div class="box-icon">
<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<div class="pagedList" data-tms-target="#AuditTable">
@Html.PagedListPager(Model , page => Url.Action("Index", new { page }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "AuditTable" , LoadingElementId="progress2"}))
</div>
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress2" />
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model=>model.SingleOrDefault().UserName)
</th>
<th>
@Html.DisplayNameFor(model=>model.SingleOrDefault().AuditAction.Name)
</th>
<th>
@Html.DisplayNameFor(model=>model.SingleOrDefault().TechnologyType.Name)
</th>
<th>
@Html.DisplayNameFor(model=>model.SingleOrDefault().Technology.Tag)
</th>
</tr>
</thead>
<tbody>
@*@foreach (var item in Model.OrderByDescending(a=>a.DateTimeStart)) {
<tr>*@
@foreach (var item in Model) {
<tr>
<td>
@item.UserName
</td>
<td>
@(item.AuditAction == null ? "None" : item.AuditAction.Name)
</td>
<td>
@(item.TechnologyType == null ? "None" : item.TechnologyType.Name)
</td>
<td>
@Html.DisplayTextFor(_ => item.Technology.Tag).ToString()
</td>
</tr>
}
</tbody>
</table>
<img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress3" />
<div class="pagedList" data-tms-target="#ServerTable">
@Html.PagedListPager(Model , page => Url.Action("Index", new { page }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "AuditTable" , LoadingElementId="progress3"}))
</div>
</div></div></div></div>
Now If the user do a search using the searchTerm or the typeid the Ipaged will show number of pages equal to the objects that have the same typeid or the same searchTerm (for example Page 1 , Page 2). But when the user clicks on the page2 link , the paging will show all the objects and will ignore the typeid & the searchTerm, so how I can force the Ipaged list to do the paging on the records that was retrieved from the first action method call, which include the searchTerm or the typeid in the action method call?