因為我們的分頁 支援通過下拉框選擇頁碼後自動跳頁 有點兒像webform 的autopostback 而我們又是get 提交版的 需要解決一個問題 選擇後自動跳頁 需要帶上以前的查詢條件 不能跳完頁以後 查詢條件消失了
用一個隱藏的a 標籤 這個a 標籤產生的串連 儲存了當前的查詢條件等 他的頁面數 顯示成"*pageindex* 當我們選擇下拉框跳頁後 用選擇的值 替換這個"*pageindex* 然後跳轉到當前href 則解決了上述問題
上代碼
<text>跳轉至</text>
<select id="pageselect" onchange="selectchange()">
@for (int i = 1; i <=@Model.TotalPageCount; i++)
{
var selected = "";
if (i==Model.CurrentPageIndex)
{
selected = "selected='selected'";
}
<option value="@i" @selected>@i</option>
}
</select>
{
dict["PageIndex"] = "*pageindex*";
}
<a style="display:none" id="pagelink" href="@Url.RouteUrl(dict)" ></a>
//
<script type="text/javascript">
function selectchange() {
var pageselect = document.getElementById("pageselect");
var pageselectValue = pageselect.options[pageselect.selectedIndex].value;
var linkdom= document.getElementById("pagelink");
var href = linkdom.href;
href = href.replace("*pageindex*", pageselectValue);
window.location = href;
}
</script>
<text>頁</text>