PagedListを使用するページがありますが、並べ替えに使用されるドロップダウン リストも含まれています。問題は、誰かがドロップダウンリスト項目をソートに使用するときはいつでも、「次へ」または「戻る」を押すたびに、ドロップダウンリスト項目がデフォルトに復元され、プログラムがデフォルトの (基本的に空白の) ソートでコントローラーを実行することです。 2 ページ目以降 (および戻る) に移動すると、並べ替えられたアイテムが失われます。
このページで使用するコントローラーは次のとおりです。
public ActionResult Index(FormCollection dropDownSelection, string currentFilter, int? page)
{
//security
if (!Security.IsViewer(User)) return RedirectToAction("Message", "Home", new { id = 2 });
if (ViewBag.Level == 0) return RedirectToAction("Message", "Home", new { id = 2 });
if (!(Request.HttpMethod == "GET"))
{
page = 1;
}
string table = String.IsNullOrWhiteSpace(dropDownSelection["Table"]) ? "%" : dropDownSelection["Table"];
string issue = String.IsNullOrWhiteSpace(dropDownSelection["IssueType"]) ? "%" : dropDownSelection["IssueType"];
string status = String.IsNullOrWhiteSpace(dropDownSelection["Status"]) ? "%" : dropDownSelection["Status"];
var followUpItem = from follow in db.FollowUpItems
where (follow.TableName.Equals(table) || table.Equals("%")) &&
(follow.IssueType.Equals(issue) || issue.Equals("%")) &&
(follow.Status.Equals(status) || status.Equals("%"))
orderby follow.Id
select follow;
int pageNumber = (page ?? 1);
int pageSize = 10;
return View(followUpItem.ToPagedList(pageNumber, pageSize));
}
ビューのドロップダウン リストは次のとおりです。
<select name="Table" title="Table" style="font-size:8pt;">
<option value="%">--Table Name--</option>
<option value="AgentContEd">CE</option>
<option value="AgentProductTraining">PT</option>
</select>
<select name="IssueType" style="font-size:8pt;">
<option value="%">--Issue Type--</option>
<option value="W">Warning</option>
<option value="E">Error</option>
</select>
<select name="Status" style="font-size:8pt;">
<option value="%">--Status Type--</option>
<option value="O">Open</option>
<option value="U">Under Review</option>
</select>
そして (念のため) 以下は<div>
、ビューに PagedList ナビゲーション ボタンを含むものです。
<div>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
of @Model.PageCount
@if (Model.HasPreviousPage)
{
@Html.ActionLink("<<", "Index", new { page = 1, sortOrder = ViewBag.CurrentSort, searchString = ViewBag.CurrentFilter, currentFilter = ViewBag.CurrentFilter })
@Html.Raw(" ");
@Html.ActionLink("< Prev", "Index", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, searchString = ViewBag.CurrentFilter, currentFilter = ViewBag.CurrentFilter })
}
else
{
@:<<
@Html.Raw(" ");
@:< Prev
}
@if (Model.HasNextPage)
{
@Html.ActionLink("Next >", "Index", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, searchString = ViewBag.CurrentFilter, currentFilter = ViewBag.CurrentFilter })
@Html.Raw(" ");
@Html.ActionLink(">>", "Index", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort, searchString = ViewBag.CurrentFilter, currentFilter = ViewBag.CurrentFilter })
}
else
{
@:Next >
@Html.Raw(" ")
@:>>
}
</div>